1.在nginx/conf/nginx.conf中添加:
include conf.d/*.conf;
2.在同级目录下新建conf.d文件夹,在conf.d文件夹中新建自定义配置文件,如:cms.conf
upstream cms_server { server localhost:8080; } server { listen 80; server_name www.aa.com; location / { proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://cms_server; } } server { listen 80; server_name www.bb.com; location / { proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://cms_server; } } server { listen 80; server_name www.cc.com; location / { proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://cms_server; } } server { listen 80; server_name www.dd.com; location / { proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://cms_server; } }