Reputation: 5428
Here is my nginx config
server {
listen 80;
server_name _;
location / {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://flask:8001;
}
location /socket.io {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_buffering off;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_pass http://flask:8001/socket.io;
}
}
for app based on this code
As a result, I can't connect to websocket from my client page by code
var socket = io.connect(location.protocol + '//' + document.domain + ':' + (location.port || 80) + namespace)
When I try to use include proxy_params;
line in nginx config I get 2018/03/06 19:52:06 [emerg] 1#1: open() "/etc/nginx/proxy_params" failed (2: No such file or directory) in /etc/nginx/conf.d/default.conf:6
Where I'm wrong and how to allow nginx to retrieve websocket connections?
Upvotes: 0
Views: 1781
Reputation: 1387
This worked for me in tomcat. should work with other web applications if you change root
, error_log
, and proxy_pass
and config your own time outs.
server {
listen 80;
listen 443 ssl;
server_name x.y.com;
root /opt/tomcat/webapps/;
error_log /var/logs/nginx/x.y.com.log debug;
ssl_certificate /root/program/ssl/certificate.pem;
ssl_certificate_key /root/program/ssl/certificate.key;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Connection "";
proxy_connect_timeout 4000s;
proxy_read_timeout 4000s;
#proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#proxy_set_header X-Forwarded-Proto $proxy_x_forwarded_proto;
proxy_pass http://127.0.0.1:8080/;
}
Also added this to my http config
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
Upvotes: 2