引用子配置
- 在主配置上添加
include /etc/nginx/conf.d/*.conf;
- 创建子配置
cd /etc/nginx/conf.d
sudo touch xxx.conf
sudo vi xxx.conf
Nginx反向代理配置
# 编辑nginx配置文件,添加以下内容
# vim /usr/local/nginx/conf/nginx.conf
upstream applications {
server 192.168.68.43:8081 weight=1;
server 192.168.68.45:8082 weight=1;
}
server {
listen 80; # 代理端口
server_name localhost;
location / {
proxy_pass http://applications; #代理的端口
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Real-Port $remote_port;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
网友评论