Skip to content

Instantly share code, notes, and snippets.

@yosemitebandit
Created September 29, 2011 23:37
Show Gist options
  • Save yosemitebandit/1252240 to your computer and use it in GitHub Desktop.
Save yosemitebandit/1252240 to your computer and use it in GitHub Desktop.
nginx config file for flask app (behind gunicorn) with ssl
server {
listen 80;
server_name www.yupyupnope.com;
rewrite ^/(.*) https://yupyupnope.com/$1 permanent;
}
server {
listen 80;
server_name yupyupnope.com;
rewrite ^/(.*) https://yupyupnope.com/$1 permanent;
}
server {
listen 443;
ssl on;
ssl_certificate /etc/ssl/certs/yupyupnope_com.crt;
ssl_certificate_key /etc/ssl/private/yupyupnope_com.key;
server_name yupyupnope.com;
access_log /home/matt/log/yupyupnope.com/access.log;
error_log /home/matt/log/yupyupnope.com/error.log;
location / {
# checks for static files; if not found, proxy to app
try_files $uri @proxy_to_app;
}
location @proxy_to_app {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app_server;
}
}
@tayler
Copy link

tayler commented Apr 20, 2014

This was very helpful. Just noticed that nginx recommends something besides rewrites when possible: http://wiki.nginx.org/Pitfalls (search for "taxing rewrites").

It would be something like return 301 https://yupyupnope.com$request_uri; in your example.

@ar-anvd
Copy link

ar-anvd commented Sep 17, 2015

thanks, this is helpful to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment