我当前的设置时这样的,抄了很多教程,但是不懂原理感觉抄也是白抄,不管用。
server {
listen 86;
server_name box.example.com file.example.com files.example.com pan.example.com;
if ($scheme = http){
return 301 https://$server_name:88$request_uri;
}
}
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
listen 88 ssl http2;
server_name box.example.com;
error_page 497 301 =307 https://$host:$server_port$request_uri;
ssl_certificate /etc/letsencrypt/live/box.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/box.example.com/privkey.pem;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_stapling on;
ssl_stapling_verify on;
resolver 8.8.8.8 8.8.4.4 valid=300s;
resolver_timeout 5s;
location / {
proxy_pass http://localhost:8687;
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-NginX-Proxy true;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "";
proxy_max_temp_file_size 0;
proxy_read_timeout 500s;
proxy_connect_timeout 600;
proxy_send_timeout 240;
}
location /api/command/ {
proxy_pass http://localhost:8687;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
1
om2mo 2023-05-20 01:47:23 +08:00
你连域名都没改怎么反代?看上去并没有看教程
|
2
keegan 2023-05-20 01:55:21 +08:00
要么自己看看懂,要么直接 问 GPT 吧
|
3
as9567585 2023-05-20 02:37:54 +08:00
|
7
eudemonwind 2023-05-20 09:28:33 +08:00 via Android
同求,想反代谷狗,但是好像会被谷狗识别出来被 nginx 反代了,不给用
|
8
NSAgold 2023-05-20 09:55:18 +08:00
你这配置应该是没问题的。
我以前的配法和#3 给的 bing 的是一样的(不过我的没有 set_header Host $host 那行,因为用不到,后端是个 tcp 转 ws 的程序),完全没问题。nginx 出去甚至还能再套层 cloudflare 。 |
10
githmb 2023-05-20 21:57:42 +08:00
proxy_set_header Connection "Upgrade";
|
11
cquan 2023-05-20 23:05:47 +08:00
我设置过,怎么设都不行,然后发现好像不是 nginx 的问题,是 python 的 uwsgi 问题。
|
12
julyclyde 2023-05-21 10:59:14 +08:00
关键在于那两个 header
|
13
zanelee 2023-06-05 14:07:18 +08:00
command 的那个 location 加一下 proxy_set_header Connection "Upgrade";试试
|
15
zanelee 2023-06-05 15:11:07 +08:00
去试了一下,出现了这种情况,我的是因为是跨域。filebrowser 的日志也会报错 websocket: request origin not allowed by Upgrader.CheckOrigin 。看了 OP 后面给出的控制台报错的 url 和 nginx 配置的 url ,感觉就是因为这个 wss 请求的时候请求头的 Orgin 和代理过去的请求头的 Host 不一致造成的。
|
16
tyit 2023-06-08 16:13:19 +08:00
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; 试试这两个 |