Deployment Recipes Part 4 – Python, Web2py, Apache and Debian

Working with web2py conf file. This is an important part where we are configuring web2py conf file. Follow the steps below to configure it for your vps server. There might be some modifications required to this file if you are using a system other than debian.

2) Create a web2py.conf file in this folder /etc/apche2/

Contents of this file –  as-is no changes

<VirtualHost *:443>

  ServerName web2py.example.com

  SSLEngine on

  SSLCertificateFile /etc/apache2/ssl/server.crt

  SSLCertificateKeyFile /etc/apache2/ssl/server.key

  WSGIProcessGroup web2py

  WSGIScriptAlias / /home/www-data/web2py/wsgihandler.py

  <Directory /home/www-data/web2py>

    AllowOverride None

    Order Allow,Deny

    Deny from all

    <Files wsgihandler.py>

      Allow from all

    </Files>

  </Directory>

  AliasMatch ^/([^/]+)/static/(?:_[\d]+.[\d]+.[\d]+/)?(.*)         /home/www-data/web2py/applications/$1/static/$2

  <Directory /home/www-data/web2py/applications/*/static/>

    Order Allow,Deny

    Allow from all

  </Directory>

  CustomLog /private/var/log/apache2/access.log common

  ErrorLog /private/var/log/apache2/error.log

</VirtualHost>

          3) Changes in /etc/apache2/sites-available/

default – The file should look like this (no changes required)

4) Create a new file called web2py in /etc/apache2/sites-available/

Contents of this file as-in (no changes needed) –

<VirtualHost *:80>

  ServerName web2py.example.com

  WSGIDaemonProcess web2py user=www-data group=www-data display-name=%{GROUP}

  WSGIProcessGroup web2py

  WSGIScriptAlias / /home/www-data/web2py/wsgihandler.py

#This is Apache 2.2.x permission syntax. See Apache docs for 2.4 syntax

# http://httpd.apache.org/docs/2.4/upgrading.html#run-time

  <Directory /home/www-data/web2py>

    AllowOverride None

    Order Allow,Deny

    Deny from all

    <Files wsgihandler.py>

      Allow from all 

    </Files>

  </Directory>

  AliasMatch ^/([^/]+)/static/(?:_[\d]+.[\d]+.[\d]+/)?(.*)            /home/www-data/web2py/applications/$1/static/$2

  <Directory /home/www-data/web2py/applications/*/static/>

    Order Allow,Deny

    Allow from all

  </Directory>

  <Location /admin>

  Deny from all

  </Location>

  <LocationMatch ^/([^/]+)/appadmin>

  Deny from all

  </LocationMatch>

  CustomLog /private/var/log/apache2/access.log common

  ErrorLog /private/var/log/apache2/error.log

</VirtualHost>

5) Restart Apache

systemctl restart apache2.service

If all was configured properly then try accessing your domain it should re-direct the requests to web2py and land in your application. If not check troubleshooting section below. In the next part we would look at the troubleshooting aspects of this configuration and others as required. Stay focused!

Dhakate Rahul

Dhakate Rahul

Leave a Reply

Your email address will not be published. Required fields are marked *