Nginx配置 代理服务器 web服务器 负载均衡服务器 多个服务共用一个端口配置

events {
    worker_connections  1024;
}

http {
    include                 mime.types;
    default_type            application/octet-stream;
    #access_log             logs/access.log  main;
    sendfile                on;
    keepalive_timeout       65;
    gzip                    on;


    # 配置共用端口
    server {
        listen 8893;
        server_name  localhost;
        location /lb/ {
            proxy_set_header Host $http_host;
            proxy_set_header X-real-ip $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            # 设置负载均衡地址
            proxy_pass http://load_balance/;
        }
        location /qy/ {
            proxy_set_header Host $http_host;
            proxy_set_header X-real-ip $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            # 设置代理服务地址
            proxy_pass http://localhost:8892/;
        }
    }


    # 配置单个代理
    server {
        listen 8890;
        server_name localhost;
        location / { # 映射为监听端口的请求路径
            # 设置代理映射的真实地址
            proxy_pass http://192.168.1.222:3333/;
        }
    }


    # 配置加权负载均衡
    upstream load_balance {
        server 192.168.1.222:3333 weight=10;
        server 192.168.1.222:8686 weight=10;
        server 192.168.1.222:8989 weight=10;
    }
    server {
        listen 8891;
        server_name  localhost;
        location / {
            proxy_pass http://load_balance/;
        }
    }


    # 配置web服务器
    server {
        listen 8892;
        server_name localhost;
        index index.html index.html;
        root  D:\develop\Apache24\htdocs\qy_html;
        # access_log  ./logs/8892.log;
    }
}
©️2020 CSDN 皮肤主题: 撸撸猫 设计师:设计师小姐姐 返回首页