Last active
March 12, 2018 12:35
-
-
Save 17twenty/7da9248a462f99befdbc8a7e958c1dd1 to your computer and use it in GitHub Desktop.
Websocket Nginx Configuration with Go App
This file contains 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 goapp-server.curiola.com; | |
location / { | |
proxy_pass http://websocket; | |
proxy_http_version 1.1; | |
proxy_redirect off; | |
proxy_set_header Upgrade $http_upgrade; | |
proxy_set_header Connection $connection_upgrade; | |
proxy_set_header Host $http_host; | |
proxy_set_header X-Real-IP $remote_addr; | |
} | |
} | |
server { | |
listen 443; | |
server_name goapp-server.curiola.com; | |
ssl_verify_client off; | |
ssl on; | |
ssl_certificate /var/nginx-websocket/conf/ssl/cert.pem; | |
ssl_certificate_key /var/nginx-websocket/conf/ssl/cert.pem; | |
ssl_ciphers RC4:AES128-SHA:TLSv1:!AECDH:!ADH:!DH:!EDH:!LOW:!SSLv2:!EXP:!NULL; | |
ssl_prefer_server_ciphers on; | |
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; | |
ssl_session_cache shared:SSL:10m; | |
ssl_session_timeout 10m; | |
keepalive_timeout 360; | |
send_timeout 360; | |
client_header_timeout 360; | |
client_body_timeout 360; | |
location / { | |
proxy_pass http://websocket; | |
proxy_http_version 1.1; | |
proxy_redirect off; | |
proxy_set_header Upgrade $http_upgrade; | |
proxy_set_header Connection $connection_upgrade; | |
proxy_set_header Host $http_host; | |
proxy_set_header X-Real-IP $remote_addr; | |
} | |
} | |
server { | |
listen 127.0.0.1:8080; | |
server_name localhost; | |
root /var/nginx/null; | |
access_log off; | |
error_log off; | |
allow 127.0.0.1; | |
deny all; | |
location /status { | |
stub_status on; | |
} | |
} |
This file contains 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
user nginx; | |
worker_processes 8; | |
error_log /mnt/logs/websocket-error.log warn; | |
pid /var/run/nginx.pid; | |
events { | |
worker_connections 102400; | |
} | |
http { | |
include /var/nginx-websocket/conf/mime.types; | |
include /var/nginx-websocket/conf/nginx.upstream.conf; | |
default_type application/octet-stream; | |
server_names_hash_bucket_size 100; | |
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' | |
'$status $body_bytes_sent "$http_referer" ' | |
'"$http_user_agent" "$http_x_forwarded_for"'; | |
access_log /mnt/logs/websocket-access.log main; | |
client_body_temp_path /var/nginx-websocket/client_body_temp; | |
proxy_temp_path /var/nginx-websocket/proxy_temp; | |
fastcgi_temp_path /var/nginx-websocket/fastcgi_temp; | |
uwsgi_temp_path /var/nginx-websocket/uwsgi_temp; | |
scgi_temp_path /var/nginx-websocket/scgi_temp; | |
client_body_timeout 360; | |
client_header_timeout 360; | |
keepalive_timeout 360; | |
send_timeout 1200; | |
ignore_invalid_headers on; | |
recursive_error_pages on; | |
sendfile on; | |
server_name_in_redirect off; | |
server_tokens off; | |
tcp_nodelay on; | |
tcp_nopush on; | |
map $http_upgrade $connection_upgrade { | |
default upgrade; | |
'' close; | |
} | |
upstream websocket { | |
server localhost:1334; | |
} | |
include /var/nginx-websocket/conf/conf.d/*.conf; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can change the proxy_pass as follows to allow path rewriting: