1.手写server语句
vim /etc/nginx/conf.d/ip.conf
server {
listen 80;
server_name cs.ip.com;
location / {
proxy_pass http://10.0.0.52:80;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
2.修改nginx主配置文件,修改日志格式(选做)
vim /etc/nginx/nginx.conf
log_format main ‘lbIP$remote_addr - 用户$remote_user 本地时间[$time_local] "请求的方法和协议$request" ‘
‘状态码$status 响应字节数$body_bytes_sent "从哪来$http_referer" ‘
‘"浏览器配置$http_user_agent" --- "$http_x_forwarded_for";
3.使用scp命令依次推送db01上的 .conf文件
scp /etc/nginx/conf.d/ip.conf root@10.0.0.52:/etc/nginx/conf.d/
scp /etc/nginx/conf.d/ip.conf root@10.0.0.53:/etc/nginx/conf.d/
scp /etc/nginx/conf.d/ip.conf root@10.0.0.54:/etc/nginx/conf.d/
4.修改/etc/nginx/conf.d/ip.conf文件,代理相应的代理机
vim /etc/nginx/conf.d/ip.conf
5.启动nginx,并加入开机自启动
systemctl start nginx
systemctl enable nginx
6.域名解析
10.0.0.51 cs.ip.com
7.监控nginx日志
tailf /var/log/nginx/access.log
8.浏览器访问cs.ip.com
原文:https://www.cnblogs.com/syy1757528181/p/12944252.html