Last active
December 21, 2023 12:58
-
-
Save osharim/8263714 to your computer and use it in GitHub Desktop.
Nginx reverse proxy with Django & Node
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
#Django Config | |
server { | |
server_name domain.com; | |
access_log on; | |
location / { | |
proxy_pass http://127.0.0.1:8001; | |
proxy_set_header X-Forwarded-Host $server_name; | |
proxy_set_header X-Real-IP $remote_addr; | |
add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM NAV"'; | |
} | |
} | |
#Nodejs Config | |
server{ | |
server_name subdomain.domain.com; | |
access_log /var/log/nginx/me.log; | |
location / { | |
proxy_pass http://127.0.0.1:8002; | |
proxy_http_version 1.1; | |
proxy_set_header Upgrade $http_upgrade; | |
proxy_set_header Connection "upgrade"; | |
proxy_set_header Host $host; | |
#IMPORTANT | |
#Must allow access to this origin resource http://subdomain.domain.com; | |
#if is not set , you will get CORS message and the websockets will be blocked | |
proxy_set_header Access-Control-Allow-Origin http://subdomain.domain.com; | |
proxy_set_header 'Access-Control-Allow-Headers' 'X-Requested-With,Accept,Content-Type, Origin'; | |
proxy_set_header X-NginX-Proxy true; | |
proxy_redirect off; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nginx works as a inverse proxy , and are sending the HTTP request to each application.
IMPORTAT : works over nginx version > 1.4.0 , if not , please update.
Nodejs and Websockets through nginx :
Nginx config below allow to Node.js transport data through websockets on port 80.
e.g.
Client browser ( HTTP Request)
|
|
Nginx ( As a inverse proxy)
|
|
Django:80 Nodejs:80 ( Both in port 80 )
domain.com subdomain.domain.com ( Domains to send each HTTP request through our inverse proxy )
*Config ports:
( note : As WSGI server Guinicorn is a good option for run django applications )
To monitor and control a number of processes on UNIX check out http://supervisord.org/