Websocket (wss) connection issue (status 200 instead 101) between two nginx systems
YAGA
nginx-forum at forum.nginx.org
Sat Apr 18 21:39:38 UTC 2020
Hello,
I’ve a websocket (wss) connection issue (status 200 instead 101) between a
“server” (running nginx/1.14.2 reverse proxy) and a “black box” (running
nginx/1.8.1 web server with websocket).
The “server” has access to Internet and to the local network where is
connected the “black box”. I called it “black box” because I can’t change
anything except the nginx config file.
>From local network, the nginx web site of the “black box” is working
properly including websocket connection.
>From Internet, the “server”, the nginx reverse proxy gives me an access to
the nginx web site of the “black box” everything works except the websocket,
from my web browser I receive a status 200 but I should get 101 switching
protocol.
I’ve tried different setup without success.
Please let me know what you think,
Thanks a lot,
Regards,
YAGA
The “black box” wss websocket uses 80 (which is not usual) and its https
website uses 443.
“black box” web server nginx config (extract)
server {
listen 443 ssl;
ssl_certificate /opt/xxx/cert.crt;
ssl_certificate_key /opt/xxx/cert.key;
server_name localhost;
proxy_buffering off;
location / {
root /opt/xxx/web;
try_files $uri $uri/ /index.html;
}
location /websocket {
proxy_pass https://127.0.0.1:80;
}
location /api/ {
proxy_pass https://127.0.0.1:80;
}
location /static/ {
root /opt/xxx/website;
expires 10d;
}
“server” reverse proxy nginx config (extract)
server {
listen 443 ssl;
listen 80 ssl;
server_name my_server.xyz;
client_max_body_size 100M;
proxy_buffering off;
proxy_set_header X-Forwarded-For
$proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
location / {
proxy_pass https://192.168.1.20/;
auth_basic "Private";
auth_basic_user_file /etc/nginx/.htpasswd;
}
location /api/ {
proxy_pass https://192.168.1.20:80/api/;
auth_basic off;
}
location /websocket {
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection upgrade;
proxy_http_version 1.1;
proxy_set_header Origin "";
proxy_pass https://192.168.1.20:80/;
auth_basic off;
}
}
Posted at Nginx Forum: https://forum.nginx.org/read.php?2,287709,287709#msg-287709
More information about the nginx
mailing list