running two web2py instances on the same server under apache wsgi mod

92 views
Skip to first unread message

Manuele Pesenti

unread,
Jan 21, 2020, 6:37:55 AM1/21/20
to web2py-users
Hi!

If I need to manage on the same server two different web2py instances
(for example for having two distinct versions of web2py running) what
are the differences I have to consider with what reported in
documentation[1]?

At the moment I already have the first instance running through wsgi mod
using this configuration

<VirtualHost *:80>

  ServerAdmin d...@colouree.com
  ServerName apps.mycompany.com

  RewriteEngine On
  RewriteCond %{HTTPS} !=on
  RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]

  CustomLog /var/log/apache2/access-apps.log common
  ErrorLog /var/log/apache2/apps.error.log
</VirtualHost>

<VirtualHost *:443>

  ServerAdmin d...@colouree.com
  ServerName apps.mycompany.com

  SSLEngine on

  WSGIDaemonProcess web2py python-home=/path/to/pyenv27 user=myuser
group=mygroup processes=1 threads=1
  WSGIProcessGroup web2py
  WSGIScriptAlias / /path/to/web2py/wsgihandler.py
  WSGIPassAuthorization On

  <Directory /path/to/web2py>
    AllowOverride None
    Require all denied
    <Files wsgihandler.py>
      Require all granted
    </Files>
  </Directory>

      AliasMatch ^/([^/]+)/static/(?:_[\d]+.[\d]+.[\d]+/)?(.*)
/path/to/web2py/applications/$1/static/$2

  <Directory /path/to/web2py/applications/*/static/>
    Options -Indexes
    ExpiresActive On
    ExpiresDefault "access plus 1 hour"
    Require all granted
  </Directory>

  Include /etc/letsencrypt/options-ssl-apache.conf

  CustomLog /var/log/apache2/ssl-apps-access.log common
  ErrorLog /var/log/apache2/apps-error.log
  ServerAlias applications.colouree.com
  SSLCertificateFile /etc/letsencrypt/live/apps.mycompany.com/fullchain.pem
  SSLCertificateKeyFile
/etc/letsencrypt/live/apps.mycompany.com/privkey.pem
</VirtualHost>

can I simply duplicate it changing essentials informations such
WSGIDaemonProcess definition (I'd like to specify even the path to a
different virtualenv based on python 3 in the second case) and other stuff?

Thank you very much

Best regards

    Manuele

[1] http://web2py.com/books/default/chapter/29/13/deployment-recipes

Tim Nyborg

unread,
Jan 21, 2020, 6:58:43 AM1/21/20
to web2py-users
Yes, that should work.

I have three web2py instances on a server running nginx/uwsgi, and the principle's the same: slightly different configs for each instance, pointing to separate source files.

Manuele Pesenti

unread,
Jan 21, 2020, 8:59:15 AM1/21/20
to web...@googlegroups.com
Thank you Tim,

I tried but restarting apache and accessing the instance the browser
takes a long time to respond and I get this error in log:

ImportError: No module named site

This is how my apache configuration looks like if could be of any help
to understand the problem:

<VirtualHost *:443>

  ServerAdmin d...@colouree.com
  ServerName lab.mycompany.com

  SSLEngine on

  WSGIDaemonProcess laboratory python-home=/path/to/pyenv36 user=myuser
group=myuser processes=1 threads=1
  WSGIProcessGroup laboratory
  WSGIScriptAlias / /path/to/web2py/wsgihandler.py
  WSGIPassAuthorization On

  <Directory /path/to/web2py>
    AllowOverride None
    Require all denied
    <Files wsgihandler.py>
      Require all granted
    </Files>
  </Directory>

  AliasMatch ^/([^/]+)/static/(?:_[\d]+.[\d]+.[\d]+/)?(.*)
/path/to/web2py/applications/$1/static/$2

  <Directory /path/to/web2py/applications/*/static/>
    Options -Indexes
    ExpiresActive On
    ExpiresDefault "access plus 1 hour"
    Require all granted
  </Directory>

  CustomLog /var/log/apache2/ssl-lab-access.log common
  ErrorLog /var/log/apache2/lab-error.log
  ServerAlias laboratory.mycompany.com
  Include /etc/letsencrypt/options-ssl-apache.conf
  SSLCertificateFile /etc/letsencrypt/live/lab.mycompany.com/fullchain.pem
  SSLCertificateKeyFile /etc/letsencrypt/live/lab.mycompany.com/privkey.pem
</VirtualHost>

On 21/01/20 12:58, Tim Nyborg wrote:
> Yes, that should work.

Manuele Pesenti

unread,
Jan 21, 2020, 9:10:59 AM1/21/20
to web2py-users

On 21/01/20 14:59, Manuele Pesenti wrote:
> Thank you Tim,
>
> I tried but restarting apache and accessing the instance the browser
> takes a long time to respond and I get this error in log:
>
> ImportError: No module named site

Could it be related to this https://stackoverflow.com/a/41006418/1039510 ?


> When using a Python virtual environment with mod_wsgi, it is very
important that it has been created using the same Python installation
that mod_wsgi was originally compiled for. It is not possible to use a
Python virtual environment to force mod_wsgi to use a different Python
version, or even a different Python installation.
>
> You cannot for example force mod_wsgi to use a Python virtual
environment created using Python 3.5 when mod_wsgi was originally
compiled for Python 2.7. This is because the Python library for the
Python installation it was originally compiled against is linked
directly into the mod_wsgi module.
>
> So most likely what is happening is that mod_wsgi is compiled for
Python 2.6. You cannot in this case force it to use a Python virtual
environment created from Python 2.7. When you do this, you will get the
error you see about site module being missing.

So I guess I have to try using the second web2py (R-2.18 under python3
virtualenv) instance through mod_proxy... right?

Cheers

    Manuele

Manuele Pesenti

unread,
Jan 21, 2020, 10:30:07 AM1/21/20
to web2py-users

On 21/01/20 15:10, Manuele Pesenti wrote:

So I guess I have to try using the second web2py (R-2.18 under python3 virtualenv) instance through mod_proxy... right?

So I'm trying to run a web2py (R-2.18.3) instance for deploy purposes using apache mod_proxy.

First I want to install the necessary daemon... I'm following the documentation[1] but without success,
it seams the daemon is not running after starting it. How can I log errors? I cannot find them, this are the only information I have found:

# service web2py218 stop
# service web2py218 start
# service web2py218 status
● web2py218.service - LSB: web2py initscript
   Loaded: loaded (/etc/init.d/web2py218; generated)
   Active: active (exited) since Tue 2020-01-21 16:20:46 CET; 3s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 31480 ExecStop=/etc/init.d/web2py218 stop (code=exited, status=1/FAILURE)
  Process: 31514 ExecStart=/etc/init.d/web2py218 start (code=exited, status=0/SUCCESS)

Jan 21 16:20:46 Ubuntu-1804-bionic-64-nextcloud systemd[1]: Starting LSB: web2py initscript...
Jan 21 16:20:46 Ubuntu-1804-bionic-64-nextcloud web2py218[31514]:  * Starting Web Framework web2py218
Jan 21 16:20:46 Ubuntu-1804-bionic-64-nextcloud web2py218[31514]:    ...done.
Jan 21 16:20:46 Ubuntu-1804-bionic-64-nextcloud systemd[1]: Started LSB: web2py initscript.

When I try to access the web2py instance through ssh tunneling it says:

channel 3: open failed: connect failed: Connection refused

Looking in syslog I read:

# tail /var/log/syslog
Jan 21 16:20:41 Ubuntu-1804-bionic-64-nextcloud web2py218[31480]:  * Stopping Web Framework web2py218
Jan 21 16:20:41 Ubuntu-1804-bionic-64-nextcloud web2py218[31480]: start-stop-daemon: warning: failed to kill 31269: No such process
Jan 21 16:20:41 Ubuntu-1804-bionic-64-nextcloud web2py218[31480]:    ...done.
Jan 21 16:20:41 Ubuntu-1804-bionic-64-nextcloud systemd[1]: web2py218.service: Control process exited, code=exited status=1
Jan 21 16:20:41 Ubuntu-1804-bionic-64-nextcloud systemd[1]: web2py218.service: Failed with result 'exit-code'.
Jan 21 16:20:41 Ubuntu-1804-bionic-64-nextcloud systemd[1]: Stopped LSB: web2py initscript.
Jan 21 16:20:46 Ubuntu-1804-bionic-64-nextcloud systemd[1]: Starting LSB: web2py initscript...
Jan 21 16:20:46 Ubuntu-1804-bionic-64-nextcloud web2py218[31514]:  * Starting Web Framework web2py218
Jan 21 16:20:46 Ubuntu-1804-bionic-64-nextcloud web2py218[31514]:    ...done.
Jan 21 16:20:46 Ubuntu-1804-bionic-64-nextcloud systemd[1]: Started LSB: web2py initscript.

This is my script version: http://paste.debian.net/hidden/e3917c71/

Thank you for any help.

Best regards

    Manuele

[1] http://web2py.com/books/default/chapter/29/13/deployment-recipes#Start-as-Linux-daemon

Manuele Pesenti

unread,
Jan 22, 2020, 5:56:31 AM1/22/20
to web2py-users

Hi!

At the moment I solved applying a debian daemon script template[1] I found with a simplified run script such like the one here under (saved in some runscript.sh file):

NAME=web2py
PIDDIR=/var/run/$NAME
PIDFILE=$PIDDIR/$NAME.pid
/path/to/bin/python /path/to/web2py/web2py.py -a "<recycle>" --pid_filename=$PIDFILE -i 127.0.0.1 -p 8000

So I have substituted as required in the documentation recurrences of following tokens:

  • <NAME> = web2py
  • <DESCRIPTION> = Web framework
  • <COMMAND> = /path/to/runscript.sh
  • <USER> = myuser

My suspect is that there is some incompatibility of the official daemon script [2] with my Ubuntu 18.6 LTS environment, I would like to help in debugging the script if possible but I won't be able to find any error log related to the daemon failure... Let me know how can I would be of any help.

[1] https://gist.github.com/naholyr/4275302

[2] https://github.com/web2py/web2py/blob/R-2.18.3/scripts/web2py.ubuntu.sh

Best regards

    Manuele

Reply all
Reply to author
Forward
0 new messages