Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save osharim/8263714 to your computer and use it in GitHub Desktop.
Save osharim/8263714 to your computer and use it in GitHub Desktop.
Nginx reverse proxy with Django & Node
#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;
}
}
@osharim
Copy link
Author

osharim commented Jan 5, 2014

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:

  • Django is running on 127.0.0.1:8001

( note : As WSGI server Guinicorn is a good option for run django applications )

  • Nodejs is running on 127.0.0.1:8002

To monitor and control a number of processes on UNIX check out http://supervisord.org/

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