" name="sm-site-verification"/>
侧边栏壁纸
博主头像
PySuper 博主等级

千里之行,始于足下

  • 累计撰写 231 篇文章
  • 累计创建 15 个标签
  • 累计收到 2 条评论

目 录CONTENT

文章目录

Nginx 反向代理+负载均衡

PySuper
2024-11-20 / 0 评论 / 0 点赞 / 22 阅读 / 0 字
温馨提示:
所有牛逼的人都有一段苦逼的岁月。 但是你只要像SB一样去坚持,终将牛逼!!! ✊✊✊

nginx.conf

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

events {
    worker_connections 4096;
    use epoll;
    multi_accept on;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   75;
    types_hash_max_size 2048;

    default_type        application/octet-stream;
    gzip on;
    gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
    gzip_min_length 1024;

    # LB负载均衡
    upstream front_servers {
        server front_server_ip_1:prot weight=2 max_fails=3 fail_timeout=30s;
        server front_server_ip_2:prot weight=1 max_fails=3 fail_timeout=30s;
    }

    upstream end_servers {
        server end_server_ip_1:prot weight=2 max_fails=3 fail_timeout=30s;
        server end_server_ip_2:prot weight=1 max_fails=3 fail_timeout=30s;
    }

    # 添加 域名-upstream 的映射
    map $server_name $upstream_servers {
        front.zhengxingtao.com front_servers;
        end.zhengxingtao.com end_servers;
    }

    server {
        # 不要修改这里监听的端口
        listen       80 default_server;
        listen       [::]:80 default_server;
        listen       443 ssl;
        listen       [::]:443 ssl;

        # 添加域名
        server_name  front.zhengxingtao.com end.zhengxingtao.com;

        # 证书配置
        ssl_certificate /etc/nginx/ssl/$server_name/pysuper.pem;
        ssl_certificate_key /etc/nginx/ssl/$server_name/pysuper.key;
        ssl_protocols TLSv1.2 TLSv1.3;
        ssl_ciphers HIGH:!aNULL:!MD5;

        location / {
            # 反向代理
            proxy_pass https://$upstream_servers;
            proxy_http_version 1.1;
            proxy_set_header Connection "keep-alive";
            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_set_header X-Forwarded-Proto $scheme;
        }

        error_page 404 /404.html;
        location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
        }
    }
}

0
  1. 支付宝打赏

    qrcode alipay
  2. 微信打赏

    qrcode weixin

评论区