Last active
February 26, 2024 07:58
-
-
Save amanjuman/8eeaeb6a23238bb6aeab8cae7dd365c9 to your computer and use it in GitHub Desktop.
Django Nginx Config
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 | |
listen 80; | |
listen [::]:80; | |
listen 443 ssl http2; | |
listen [::]:443 ssl http2; | |
# Directory & Server Naming | |
server_name exapmle.com www.exapmle.com; | |
http2_push_preload on; | |
# HTTP to HTTPS redirection | |
if ($scheme != "https") | |
{ | |
return 301 https://$host$request_uri; | |
} | |
# SSL | |
ssl_certificate /etc/letsencrypt/live/exapmle.com/fullchain.pem; | |
ssl_certificate_key /etc/letsencrypt/live/exapmle.com/privkey.pem; | |
ssl_trusted_certificate /etc/letsencrypt/live/exapmle.com/fullchain.pem; | |
# Max Upload Size | |
client_max_body_size 100M; | |
access_log off; | |
# Django Media Folder path | |
location /media | |
{ | |
alias /var/www/django/media; | |
} | |
# Static Folder Path | |
location /static | |
{ | |
alias /var/www/django/static; | |
} | |
# For UWSGI | |
#location / | |
#{ | |
# proxy_pass http://127.0.0.1:8000; | |
# proxy_redirect off; | |
# proxy_set_header Accept-Encoding ""; | |
# proxy_set_header Host $http_host; | |
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
# proxy_set_header X-Forwarded-Proto https; | |
# proxy_set_header X-Real-IP $remote_addr; | |
#} | |
# For Gunicorn | |
location / | |
{ | |
include proxy_params; | |
proxy_pass http://unix:/var/www/django/project.sock; | |
# Proxy Header | |
proxy_set_header Host $host; | |
proxy_set_header X-Forwarded-Scheme $scheme; | |
proxy_set_header X-Forwarded-Proto $scheme; | |
proxy_set_header X-Forwarded-For $remote_addr; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header Accept-Encoding ""; | |
# Websockets Header | |
#proxy_http_version 1.1; | |
#proxy_set_header Upgrade $http_upgrade; | |
#proxy_set_header Connection "upgrade"; | |
} | |
# Disable Hidden FIle Access Except Lets Encrypt Verification | |
location ~ /\.well-known | |
{ | |
allow all; | |
} | |
# Nginx Logging | |
access_log /var/log/nginx/exapmle.com-access.log; | |
error_log /var/log/nginx/exapmle.com-error.log warn; | |
# Robot Text Logging Off | |
location = /robots.txt | |
{ | |
allow all; | |
log_not_found off; | |
access_log off; | |
} | |
# Fav ICON Disable | |
location = /favicon.ico | |
{ | |
log_not_found off; | |
access_log off; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment