Last active
August 29, 2015 13:57
-
-
Save dhrrgn/9667299 to your computer and use it in GitHub Desktop.
Sixpack Server Nginx Proxy with SSL
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 sixpack-server.myserver.com; | |
return 301 https://$host$request_uri; | |
} | |
server { | |
listen 443 ssl; | |
server_name sixpack-server.myserver.com; | |
ssl_certificate /etc/nginx/ssl/sixpack-server.myserver.com.chained.crt; | |
ssl_certificate_key /etc/nginx/ssl/sixpack-server.myserver.com.key; | |
charset utf-8; | |
access_log /var/log/nginx/sixpack-server.myserver.com-access.log; | |
error_log /var/log/nginx/sixpack-server.myserver.com-error.log error; | |
# Don't log these things | |
location = /robots.txt { access_log off; log_not_found off; } | |
location = /humans.txt { access_log off; log_not_found off; } | |
location / { | |
proxy_pass http://127.0.0.1:5000; | |
proxy_set_header Host $host; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
# CORS Stuff | |
if ($http_origin ~* (https?://[^/]*\.?myserver\.com(:[0-9]+)?)) { | |
set $cors "true"; | |
} | |
if ($request_method = 'OPTIONS') { | |
set $cors "${cors}options"; | |
} | |
if ($request_method = 'GET') { | |
set $cors "${cors}get"; | |
} | |
if ($request_method = 'POST') { | |
set $cors "${cors}post"; | |
} | |
if ($cors = 'trueget') { | |
add_header 'Access-Control-Allow-Origin' "$http_origin"; | |
add_header 'Access-Control-Allow-Credentials' 'true'; | |
} | |
if ($cors = 'truepost') { | |
add_header 'Access-Control-Allow-Origin' "$http_origin"; | |
add_header 'Access-Control-Allow-Credentials' 'true'; | |
} | |
if ($cors = 'trueoptions') { | |
add_header 'Access-Control-Allow-Origin' "$http_origin"; | |
add_header 'Access-Control-Allow-Credentials' 'true'; | |
add_header 'Access-Control-Max-Age' 15; | |
add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS'; | |
add_header 'Access-Control-Allow-Headers' 'Authorization,Content-Type,Accept,Origin,User-Agent,DNT,Cache-Control,X-Mx-ReqToken,Keep-Alive,X-Requested-With,If-Modified-Since'; | |
add_header 'Content-Length' 0; | |
add_header 'Content-Type' 'text/plain charset=UTF-8'; | |
return 204; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment