This implementation was made using Debian 8.
-
Install packages:
aptitude install nginx supervisor
-
A. First, make the clone of your project in some area of preference on your server:
cd /store/projects/ git clone my-site.git
-
B. Create virtualenv
-
C. Install Gunicorn into venv of project:
(venv)$ pip install gunicorn
-
Access the sites-available of nginx
cd /etc/nginx/sites-available/
-
Create a file of project
vim mydomain.localhost
-
With content (Attention: Check that the chosen port is already in use (eg use command
sudo netstat -tlpn | grep 800
)):upstream MY_DOMAIN_ALIAS_NAME { server 127.0.0.1:8000; }
-
Create symbolic link of this file:
sudo ln -s /etc/nginx/sites-available/mydomain.localhost /etc/nginx/sites-enabled/
-
Create a nginx configuration file (if it already exists, you just add the contents of step 6):
sudo vim /etc/nginx/conf.d/vhost_autogen.conf
-
Inside this file vhost_autogen.conf we will add a "block" for the appointment of the service:
server { listen *:80; listen 443 ssl; server_name bancodequestoes.local.convergetecnologia.com.br; access_log /var/log/nginx/MEU_DOMINIO.access.log; error_log /var/log/nginx/MEU_DOMINIO.error.log; location /static/ { alias /path/to/static/of/project/django/; } location /media/ { alias /path/to/media/of/project/django/; } location / { proxy_pass http://MY_DOMAIN_ALIAS_NAME; proxy_read_timeout 90; proxy_connect_timeout 90; proxy_redirect off; } }
-
Once this is done, go to the /etc/hosts file and add a line:
sudo vim /etc/hosts
With content:
.... 127.0.0.1 my-domain.com ....
-
Create a supervisor configuration file:
sudo vim /etc/supervisor/conf.d/mysite.conf (Warning: Please note the .conf extension)
-
With content:
[program:MYPROJECTALIASSUPERVISOR] command=/PATH/TO/VIRTUALENV/bin/gunicorn [PROJECTNAME].wsgi:application -b 127.0.0.1:8000 -w 3 --timeout 600 --access-logfile /tmp/gunicorn.access-MYDOMAIN.log --error-logfile /tmp/gunicorn.error-MYDOMAIN.log directory=/PATH/TO/PROJECT/ user=USER-OF-BASH autostart=true autorestart=true redirect_stderr=True environment=DJANGO_SETTINGS_MODULE="app.settings"
-
All right! Now we will launch the following commands to start the settings previously made:
sudo supervisorctl reread sudo supervisorctl update sudo supervisorctl start MYPROJECTALIASSUPERVISOR
-
Lastly:
sudo service nginx restart
-
You can test the access via browser, in case of error 500 you have the log files:
/tmp/gunicorn.error-MYDOMAIN.log
OR
/tmp/gunicorn.access-MYDOMAIN.log