I'm trying to deploy my Django Project
through different application server : Apache2
, Nginx/gunicorn
, ...
It works fine with Apache2
or Nginx
, but I would like to dissociate these application server with my Django Projet
. I would like to get an environment like this :
- Server 1 (172.30.10.92) : Django Project & wsgi
- Server 2 (172.30.10.93) : Nginx/gunicorn
Why ? Because later I will have some Django applications, but I would like to use just one application server.
I think I'm making a mistake with my configuration files syntax.
I have in /etc/nginx/sites-available/DatasystemsCORE.conf :
server {
listen 8000;
server_name 172.30.10.92;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root http://172.30.10.92:/var/www/html/;
}
location / {
include proxy_params;
proxy_pass http://172.30.10.92/unix:/var/www/html/DatasystemsCORE/dscore.sock;
}
}
server_name : Is it IP adress from Django server or nginx server ? I think it's the first one but I'm not sure.
proxy_pass : I think there is an issue in my path
Then, I'm executing this command :
gunicorn --daemon --workers 3 --bind 172.30.10.92/unix:/var/www/html/DatasystemsCORE/dscore.sock 172.30.10.92:/var/www/html/DatasystemsCORE/DatasystemsCORE.wsgi
One more time, I thing there is a syntax problem because I'm getting 502 Bad Request
How I can add IP address from a distant Django server there ?
Thank you !
I found How to solve my issue and I made a tutorial (based on my case) in order to help everyone who would like to make the same thing.
My file is there : Download tutorial file
But this is the same tutorial written in English.
My Django IP server : 172.30.10.92
My Nginx IP server : 172.30.10.93
1- Install and Configure wsgi (located on Django server)
WSGI is a file created with your Django project.
The file is located in
/path/to/your/project/Myproject/wsgi.py
We have to edit this file like this :
2- Install and Configure gunicorn/supervisor (located on Django server)
In order to install gunicorn/supervisor, you have to execute in your shell :
Then, you have to create a new file in
/etc/supervisor/conf.d/Myproject.conf
which looks like this :I specified port 8080 which is the communication port between my application server and my web server.
3- Edit hosts file on nginx server (located on nginx server)
You have to edit your hosts file located to
/etc/hosts
and add a new entry to your Django server :4- New config file in nginx repository (located on nginx server)
This new file should be placed in
/etc/nginx/sites-available/Myproject.conf
The IP address corresponds to my Django server address. I specified the listen port (8080), the path to my Django project & static directory.
Then, you have to create a symbolic link to sites-enabled.
After ths operation, restart nginx service :
5- Allow nginx IP address in Django (located on Django server)
You have to edit your settings.py file in order to allow nginx IP address in ALLOWED_HOSTS :
6- Finally execute gunicorn (located on Django server)
Finally, you have to start gunicorn. You should be inside your Django root project and execute :
Now, in your browser, try to connect to your nginx server with the port :
It works !
PS : This tutorial works for me, if it doesn't work for you, maybe I missed something, or maybe you didn't make exactly like me ;)
What you're trying to do doesn't make any sense. You can certainly use a single nginx on a separate server, but gunicorn is the application server and belongs with the application.
There is no "Django server" so your first question is irrelevant. gunicorn will need to serve on a port, not a socket, and the nginx proxy_pass will point to that port.