Wednesday, February 10, 2016

how to deploy python/django application in debian/apache?

Hi,

I succeeded to run development python application: python3 ./manage.py runserver 0.0.0.0:8080

but now I need to make deployment, honestly I didn't succed to do it from august. I hope here I will get help.

first of all, settings.py had to be corrected from debug = true to DEBUG = False & ALLOWED_HOSTS = ['*',] should be with domain name, let's say: mijaw.com, ALLOWED_HOSTS = ['https://mijaw.com',]

I use debian + apache with iRedMail (I think iredmail already installed wsgi module for apache), all my sites at my VPS are redirected from port 80 to 443, visitors are forced to use httpS, it means when I tried 443 and 80, port was alrwady in use and I had to choose 8080. but I want that my python application is deployed with ssl, 443 port. 
if it is too much complicated let's try first with 8080, it doesn't matter so much,

the biggest problem for me is connecting python application (placed in root folder) with domain/apache configuration file (virtual host): /etc/apache2/sites-available/mijaw-ssl.conf
mijaw-ssl.conf is apache configuration file for domain with port 443. as I said, it is forced from 80 to 443, so, it is httpS://mijaw.com

first I will tell you my python paths:
my settings.py is located at: /root/mercury/mercury
but there is also urls.py and wsgi.py in this folder: /root/mercury/mercury
admins.py, urls.py, templates folder are located at: /root/mercury/messages
my virtualenv folder is: /root/env/bin/activate
if static folder is important, there are css,fonts,javascript and other folders: /root/mercury/static
html files are here: /root/mercury/messages/templates

my problem is: all of this should be connected with /etc/apache2/sites-available/mijaw-ssl.conf

here it is automatically created by iRedMail, I suppose it should be added similar for my python app:

<IfModule mod_ssl.c>
<VirtualHost mijaw.com:443>
 ServerAdmin webmaster@localhost
 DocumentRoot /var/www/html

SSLEngine on
# HSTS (mod_headers is required) (15768000 seconds = 6 months)
Header always set Strict-Transport-Security "max-age=15768000"
SSLCipherSuite ECDHE-RSA-AES128-GCM-SHA256.............................blah-blah

SSLHonorCipherOrder on

SSLCertificateFile /etc/ssl/certs/iRedMail.crt
SSLCertificateKeyFile /etc/ssl/private/iRedMail.key
...............

<FilesMatch "\.(cgi|shtml|phtml|php)$">
                                SSLOptions +StdEnvVars
                </FilesMatch>
                <Directory /usr/lib/cgi-bin>
                                SSLOptions +StdEnvVars
                </Directory>

Alias /iredadmin/static "/opt/www/iredadmin/static/"
WSGIScriptAlias /iredadmin "/opt/www/iredadmin/iredadmin.py/"
Alias /mail "/opt/www/roundcubemail/"
Alias /awstats/icon "/usr/share/awstats/icon/"
Alias /awstatsicon "/usr/share/awstats/icon/"
ScriptAlias /awstats "/usr/lib/cgi-bin/"
 
</VirtualHost>
</IfModule>

I checked of module wsgi is running and it is running: 
apache2ctl -t -D DUMP_MODULES
result: wsgi_module (shared)

should I add somewhere also: AddHandler wsgi-script .wsgi

so, all in all, I should connected python app placed in root folder with apache configuration and domain running with 443 port/https, so I would like secure connection for my python application.
wsgi_module (shared)

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c7cfcd0d-94a0-4832-85c6-c9da1818debf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment