宝塔面板自带了反向代理设置, 通过Nginx反向代理我们可以让网站达到加速的效果,
如果开启缓存还可以减少源服务器带宽压力,现在简单说说这个设置.
  • 以cs.iocc.online为例
  • 若cs.iocc.online源服务器为A, 反代节点服务器为B和C.
  • 假设源服务器A的IP为:173.82.206.56
  • 反代节点服务器B和C:67.230.184.21 / 47.74.192.19
  1. 首先要在反代服务器节点(B和C)上设置 hosts.

    vi /etc/hosts
  2. 输入源服务器A的IP地址, 如

    173.82.206.56   cs.iocc.online

    1.png

  3. 在反代服务器节点(B和C)上宝塔面板里新建网站:
    1.png
  4. 在宝塔网站设置内,添加反向代理:
    1.png
  5. 修改反代配置文件,添加如下代码:1.png

    代码

#PROXY-START/
location /user/
{
    expires 12h;
    if ($request_uri ~* "(php|jsp|cgi|asp|aspx)")
    {
         expires 0;
    }
    
    proxy_pass https://cs.iocc.online;
    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 REMOTE-HOST $remote_addr;
    
    #持久化连接相关配置
    #proxy_connect_timeout 30s;
    #proxy_read_timeout 86400s;
    #proxy_send_timeout 30s;
    #proxy_http_version 1.1;
    #proxy_set_header Upgrade $http_upgrade;
    #proxy_set_header Connection "upgrade";

    add_header X-Cache $upstream_cache_status;
}

location /
{
    expires 12h;
    proxy_request_buffering off;
    if ($request_uri ~* "(php|jsp|cgi|asp|aspx)")
    {
         expires 0;
    }
     location ~/user/.*\.(php|cgi)$
    {
         expires 0;
    }
    
    proxy_pass https://cs.iocc.online;
    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 REMOTE-HOST $remote_addr;
  
         location ~ (/user|/user/code|/user/code_check)?$
    {
        proxy_set_header Host cs.iocc.online;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header REMOTE-HOST $remote_addr;
        proxy_pass https://cs.iocc.online;
        proxy_set_header Accept-Encoding "";
        sub_filter_once off;
        proxy_request_buffering off;
        expires -1;
    }
    
    
    #持久化连接相关配置
    #proxy_connect_timeout 30s;
    #proxy_read_timeout 86400s;
    #proxy_send_timeout 30s;
    #proxy_http_version 1.1;
    #proxy_set_header Upgrade $http_upgrade;
    #proxy_set_header Connection "upgrade";

    add_header X-Cache $upstream_cache_status;
    proxy_cache cache_one;
    proxy_cache_key $host$uri$is_args$args;
    proxy_cache_valid 200 304 301 302 1m;
}

   
#PROXY-END/