Skip to content

Instantly share code, notes, and snippets.

@brunoqs
Last active July 3, 2019 01:18
Show Gist options
  • Save brunoqs/cd060a927414504ad341c8cdffc1c24a to your computer and use it in GitHub Desktop.
Save brunoqs/cd060a927414504ad341c8cdffc1c24a to your computer and use it in GitHub Desktop.
Easy deploy Django Apache
-----------------------Debian Requirements------------------------
python3-dev, apache2, libapache2-mod-wsgi-py3
-------------------------------WSGI-------------------------------
import os
import time
import traceback
import signal
import sys
from django.core.wsgi import get_wsgi_application
sys.path.append('/home/path/project')
# adjust the Python version in the line below as needed
sys.path.append('/home/path/env/lib/python3.6/site-packages')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")
try:
application = get_wsgi_application()
except Exception:
# Error loading applications
if 'mod_wsgi' in sys.modules:
traceback.print_exc()
os.kill(os.getpid(), signal.SIGINT)
time.sleep(2.5)
---------------------------Apache Conf Without SSL----------------------------
<VirtualHost *:80>
ServerName www.example.com.br
Redirect permanent / http://example.com.br
</VirtualHost>
<VirtualHost *:80>
ServerName example.com.br
DocumentRoot /home/path/project
WSGIScriptAlias / /home/path/project/project/wsgi.py
# adjust the following line to match your Python path
WSGIDaemonProcess example.com.br processes=2 threads=15 display-name=%{GROUP} python-home=/home/path/env
WSGIProcessGroup example.com.br
<directory /home/path/project>
AllowOverride all
Require all granted
Options FollowSymlinks
</directory>
Alias /static/ /home/path/project/static/
Alias /media/ /home/path/project/media/
<Directory /home/path/project/static>
Require all granted
</Directory>
<Directory /home/path/project/media>
Require all granted
</Directory>
</VirtualHost>
---------------------------Apache Conf With SSL----------------------------
<VirtualHost *:80>
ServerName host.com.br
RewriteEngine on
RewriteRule ^(.*)$ https://host.com.br$1 [R,L]
</VirtualHost>
<VirtualHost *:80>
ServerName www.host.com.br
RewriteEngine on
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^(.*)$ https://host.com.br$1 [R,L]
</VirtualHost>
<VirtualHost *:443>
ServerName host.com.br
DocumentRoot /home/user/code_path
WSGIScriptAlias / /home/user/code_path/code/wsgi.py
# adjust the following line to match your Python path
WSGIDaemonProcess host.com.br python-home=/home/user/code_path/code-env
WSGIProcessGroup host.com.br
<directory /home/redacao/code_ath>
AllowOverride all
Require all granted
Options FollowSymlinks
</directory>
Alias /static/ /home/user/code_path/static/
Alias /media/ /home/user/code_path/media/
<Directory /home/user/code_path/static>
Require all granted
</Directory>
<Directory /home/user/code_path/media>
Require all granted
</Directory>
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/host.com.br/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/host.com.br/privkey.pem
</VirtualHost>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment