nginx常用配置

负载均衡

upstream WEB_SERVER {
    ip_hash;
    server 10.137.172.201;
    server 10.137.172.202;
    server 10.137.172.203;
}

location ~ ^/(.*)$ {
    proxy_pass     http://WEB_SERVER;
}

反向代理

upstream APP_SERVER {
    ip_hash;
    server 10.137.172.204:3000;
    server 10.137.172.205:3000;
}

location ~ ^/apps/(.*)$ {
    proxy_set_header x-real-ip $remote_addr;
    proxy_pass http://APP_SERVER/$1?$query_string;
}

socket.io

upstream SOCKET_SERVER {
    ip_hash;
    server 10.137.172.204:3001;
    server 10.137.172.205:3001;
}

location /socket.io/ {
    proxy_pass     http://SOCKET_SERVER$request_uri;
    proxy_redirect off;

    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_http_version    1.1;
}
    原文作者:ymyang
    原文地址: https://segmentfault.com/a/1190000005911092
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞