Skip to content

Instantly share code, notes, and snippets.

@mmaridev
Created February 24, 2019 19:52
Show Gist options
  • Save mmaridev/7af0b4acd68622a41a7c1bc4df25f3d6 to your computer and use it in GitHub Desktop.
Save mmaridev/7af0b4acd68622a41a7c1bc4df25f3d6 to your computer and use it in GitHub Desktop.
Apache 2 configuration to run django apps
<VirtualHost *:80>
ServerName example.org
ServerAdmin you@example.org
DocumentRoot /var/www/html
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/?(.well-known)/
RewriteRule ^(.*) https://%{HTTP_HOST}%{REQUEST_URI}
ErrorLog ${APACHE_LOG_DIR}/error_example.log
CustomLog ${APACHE_LOG_DIR}/access_example.log combined
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost _default_:443>
ServerName example.org
ServerAdmin you@example.org
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error_example_ssl.log
CustomLog ${APACHE_LOG_DIR}/access_example_ssl.log combined
SSLEngine on
SSLCertificateFile /etc/path/to/your/certificate.pem
SSLCertificateKeyFile /etc/path/to/your/key.pem
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>
Alias /static /var/www/project/staticfiles
WSGIDaemonProcess project python-path=/var/www/project processes=2 threads=15
WSGIProcessGroup project
WSGIScriptAlias / /var/www/project/project/wsgi.py
<Directory /var/www/project/project>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>
</IfModule>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment