宝塔面板nginx+Websockets 反代 实现本地中转/远程中转&HTTP和HTTPS互转

image
点击宝塔面板的网站名-反向代理-配置文件。

本地中转

记得修改端口55555:

location ^~ / {
        proxy_redirect off;
        proxy_pass http://127.0.0.1:55555;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $http_host;
        }

远程中转HTTPS

记得修改网址 xxx.com

location ^~ / {
        proxy_pass https://xxx.com/abc;
        proxy_set_header Host xxx.com:443;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-Proto https;
}

远程中转HTTP

记得修改网址 xxx.com

location /abc {
        proxy_pass http://xxx.com/abc;
        proxy_set_header Host xxx.com:80;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-Proto http;
}

其他

中转使用CDN的网站,比如CF,需要增加2行代码

在反代的配置文件里面

两个location区块都加上:

记得修改网址 xxx.com

proxy_ssl_name xxx.com;
proxy_ssl_server_name on;