nginx反向代理模板

部署db代理机

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 [email protected]:/etc/nginx/conf.d/
scp /etc/nginx/conf.d/ip.conf [email protected]:/etc/nginx/conf.d/                      
scp /etc/nginx/conf.d/ip.conf [email protected]:/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

nginx反向代理模板_第1张图片

你可能感兴趣的:(nginx反向代理模板)