Last active
November 17, 2020 13:14
-
-
Save brunoqs/219f5e9852b718d831bce502bdd2e511 to your computer and use it in GitHub Desktop.
Easy deploy Django Nginx + gunicorn and Vuejs or Reactjs
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 Nginx + gunicorn ---------------- | |
Primeiro rode o gunicorn no repositorio do projeto: | |
$ gunicorn --bind 0.0.0.0:8000 my_academic.wsgi & | |
Depois crie a seguinte configuração no Nginx (/etc/nginx/sites-available): | |
server { | |
access_log /home/user/code_back/logs/access.log; | |
error_log /home/user/code_back/logs/error.log; | |
server_name host.com.br; | |
location / { | |
proxy_pass http://127.0.0.1:8000; | |
#As proximas linhas passam o IP real para o gunicorn nao achar que sao acessos locais | |
proxy_pass_header Server; | |
proxy_set_header X-Forwarded-Host $server_name; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_set_header Host $http_host; | |
} | |
location /static { | |
alias /home/user/code_back/static/; | |
} | |
location /media { | |
alias /home/user/code_back/media/; | |
} | |
} | |
$ sudo apt-get install nginx | |
$ cd /etc/nginx/sites-available | |
$ touch <your-config>.conf | |
$ cd /etc/sites-enabled | |
$ ln -s /etc/nginx/sites-available/<your-config> . | |
$ sudo nginx -t (para verificar se a configuração está correta) | |
$ sudo service nginx reload (botar a configuração no ar) | |
Para colocar SSL baixe utilize o let's encrypt | |
$ sudo add-apt-repository ppa:certbot/certbot | |
$ sudo apt-get update | |
$ sudo apt-get install python-certbot-nginx | |
$ sudo certbot --nginx -d example.com -d www.example.com | |
$ sudo certbot renew --dry-run (renovar certificado, adicionar no cron) | |
CRON para renovar certificado: | |
$ sudo crontab -e | |
0 0 01 */2 * /usr/bin/certbot renew --dry-run | |
30 1 * * 1 /bin/systemctl reload nginx | |
---------------- Nginx + Vue or React ---------------- | |
server { | |
server_name host.com; | |
charset utf-8; | |
root /home/user/code_front/dist; | |
index index.html index.htm; | |
# Always serve index.html for any request | |
location / { | |
root /home/user/code_front/dist; | |
try_files $uri /index.html; | |
} | |
error_log /home/user/code_front/logs/vue-app-error.log; | |
access_log /home/user/code_front/logs/vue-app-access.log; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment