Nginx反向代理基础配置



  • 将以下文件保存到:/etc/nginx/conf.d/http.conf

    upstream servers {
        server localhost:8001;
        server localhost:8002;
        server localhost:8003;
        server localhost:8004;
    }
    
    server {
        listen 9000;
    
        location / {
            proxy_pass  http://servers;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
            proxy_set_header Host $http_host;
            proxy_set_header X-NginX-Proxy true;
            proxy_redirect off;
            # Socket.IO Support
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
       }
    }
    
    

    然后运行(CentOS):systemctl restart nginx
    即可将9000端口上的请求转发到本机的:8001,8002,8003,8004端口


Log in to reply