Handle websockets in nginx.conf

This commit is contained in:
Martin Pépin 2017-08-10 16:56:03 +01:00
parent 73296ea251
commit dae418af3d

View file

@ -9,7 +9,7 @@ server {
server_name localhost; server_name localhost;
# All the trafic is routed to Daphne # All the trafic is routed to Daphne
location ~ ^/ { location / {
# A copy-paste of what we have in production # A copy-paste of what we have in production
proxy_set_header Host $http_host; proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Real-IP $remote_addr;
@ -18,21 +18,42 @@ server {
proxy_set_header X-SSL-Client-Serial $ssl_client_serial; proxy_set_header X-SSL-Client-Serial $ssl_client_serial;
proxy_set_header X-SSL-Client-Verify $ssl_client_verify; proxy_set_header X-SSL-Client-Verify $ssl_client_verify;
proxy_set_header X-SSL-Client-S-DN $ssl_client_s_dn; proxy_set_header X-SSL-Client-S-DN $ssl_client_s_dn;
# Reverse-proxy # Reverse-proxy
proxy_pass http://gestiocof; proxy_pass http://gestiocof;
} }
# Upgrading the connection when handling websockets
location /ws/ {
# A copy-paste of what we have in production
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_set_header X-SSL-Client-Serial $ssl_client_serial;
proxy_set_header X-SSL-Client-Verify $ssl_client_verify;
proxy_set_header X-SSL-Client-S-DN $ssl_client_s_dn;
# See http://nginx.org/en/docs/http/websocket.html
proxy_buffering off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://gestiocof;
}
# Static files # Static files
location ~ ^/static/ { location /static/ {
root /srv/gestiocof/static/; root /srv/gestiocof/;
access_log off; access_log off;
add_header Cache-Control "public"; add_header Cache-Control "public";
expires 7d; expires 7d;
} }
# Uploaded media # Uploaded media
location ~ ^/media/ { location /media/ {
root /srv/gestiocof/static/; root /srv/gestiocof/;
access_log off; access_log off;
add_header Cache-Control "public"; add_header Cache-Control "public";
expires 7d; expires 7d;