1. cd到/usr/local/nginx/conf/
找到 nginx.conf 配置文件文件
以下代码为配置代码
其中upstream 的backwww 要对应server.location下面的proxy_pass
worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; upstream backwww { #ip_hash;
#项目对应的端口号 server 127.0.0.1:8000; } upstream backa { #ip_hash; server 127.0.0.1:8001; } upstream backb { #ip_hash; server 127.0.0.1:8002; } server { listen 80;
#项目的访问地址 server_name www.chenzhanghui.vip; location / { 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_buffering off; proxy_pass http://backwww; } } server { listen 80;
#项目的访问地址 server_name a.chenzhanghui.vip; location / { 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_buffering off; proxy_pass http://backa; } } server { listen 80; server_name b.chenzhanghui.vip; location / { 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_buffering off; proxy_pass http://backb; } } }