记一次nginx80端口跨域问题

nginx | 2021-10-28 12:18:49

因为要转发websocket,所以我的nginx配置如下:

location /jupyterhub/ {
            proxy_pass http://127.0.0.1:8000/jupyterhub/;
                proxy_set_header Host $host:$server_port;
                proxy_set_header X-Real-Scheme $scheme;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

                # WebSocket support
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";

                proxy_read_timeout 120s;
                proxy_next_upstream error;



        }

但是后台报错

[W 2021-10-28 03:40:25.723 SingleUserNotebookApp zmqhandlers:144] Blocking Cross Origin WebSocket Attempt.  Origin: http://xx.com, Host: xx:80
[W 2021-10-28 03:40:25.724 SingleUserNotebookApp log:189] 403 GET /jupyterhub/user/admin/api/kernels/101f0c11-7d5e-4d2b-a27b-2b4e0971db2d/channels?session_id=b7886266-8c38-4a3a-a9b6-72c7a8ff5d57 (admin@103.xx.265.118) 5.41ms

很明显源地址和转发地址有不同,就是多了个端口,就是下面这个配置导致的

 proxy_set_header Host $host:$server_port;

所以只要去掉:$server_port就可以了,尝试之后果然是这样。终于解决

 

 

 

 

登录后即可回复 登录 | 注册
    
关注编程学问公众号