Skip to content

Instantly share code, notes, and snippets.

@alialavia
Created July 12, 2018 20:23
Show Gist options
  • Save alialavia/63805a95cb821c19c553d0c21a8da938 to your computer and use it in GitHub Desktop.
Save alialavia/63805a95cb821c19c553d0c21a8da938 to your computer and use it in GitHub Desktop.
server {
server_name www.example.com;
access_log /var/log/nginx/example.com.log;
error_log /var/log/nginx/example.com.error.log debug;
root /home/myuser/example.com/homepage;
sendfile on;
# if the uri is not found, look for index.html, else pass everthing to gunicorn
location / {
index index.html;
try_files $uri $uri/
@gunicorn;
}
# Django media
location /media {
alias /home/myuser/example.com/example-django/public/media; # your Django project's media files
}
# Django static files
location /static {
alias /home/myuser/example.com/example-django/public/static; # your Django project's static files
}
location @gunicorn {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
#proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect off;
proxy_pass http://0.0.0.0:8000;
}
client_max_body_size 100M;
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/www.example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/www.example.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
server_name example.com;
listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/www.example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/www.example.com/privkey.pem; # managed by Certbot
return 301 https://www.example.com$request_uri;
}
server {
if ($host = www.example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80 default_server;
listen [::]:80 default_server;
server_name example.com www.example.com;
return 301 https://$server_name$request_uri;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment