Created
October 3, 2017 19:48
-
-
Save furdarius/81b3dfbca8e5929d0efeffbfa017d54d to your computer and use it in GitHub Desktop.
Пример конфигурации для websocket vhost, при использовании nginx как proxy.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| server { | |
| listen 80; | |
| server_name ws.mysite.com; | |
| access_log off; | |
| return 301 https://$server_name$request_uri; | |
| } | |
| upstream wsserver { | |
| ip_hash; | |
| server <WEB_SOCKET_SERVER>; # В формате HOST:PORT (Например: 123.123.123.123:9999) | |
| keepalive 512; | |
| } | |
| map $http_upgrade $connection_upgrade { | |
| default upgrade; | |
| '' close; | |
| } | |
| server { | |
| listen 443 ssl; | |
| server_name ws.mysite.com; | |
| ## Strong SSL Security | |
| ## https://raymii.org/s/tutorials/Strong_SSL_Security_On_nginx.html & https://cipherli.st/ | |
| ssl on; | |
| ssl_certificate /etc/nginx/ssl/ws.mysite.com/fullchain.pem; | |
| ssl_certificate_key /etc/nginx/ssl/ws.mysite.com/privkey.pem; | |
| ssl_ciphers EECDH:+AES256:-3DES:RSA+AES:RSA+3DES:!NULL:!RC4; | |
| ssl_protocols TLSv1.1 TLSv1.2; | |
| ssl_prefer_server_ciphers on; | |
| ssl_session_cache shared:SSL:10m; | |
| ssl_session_timeout 5m; | |
| proxy_next_upstream error; | |
| proxy_set_header X-Real-IP $remote_addr; | |
| proxy_set_header X-Scheme $scheme; | |
| proxy_set_header Host $http_host; | |
| # Это для LetsEncrypt | |
| # Удобнее инклудить | |
| # include conf.d/acme.block; | |
| # но для пример оставил так | |
| location /.well-known { | |
| root /etc/letsencrypt; | |
| } | |
| # Пример от centrifugo, поэтому endpoint такой, | |
| # но может быть любой. | |
| # Этот endpoint используется при создании new WebSocket(...) | |
| location /connection { | |
| proxy_pass http://wsserver; | |
| proxy_buffering off; | |
| keepalive_timeout 65; | |
| proxy_read_timeout 60s; | |
| proxy_http_version 1.1; | |
| proxy_set_header X-Real-IP $remote_addr; | |
| proxy_set_header X-Scheme $scheme; | |
| proxy_set_header Host $http_host; | |
| proxy_set_header Upgrade $http_upgrade; | |
| proxy_set_header Connection $connection_upgrade; | |
| } | |
| location / { | |
| proxy_pass http://wsserver; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment