Deploy web2py server with Nginx in Debian

[Web design] Deploy web2py server with Nginx in Debian

Web2py is a great python web platform. However I don’t find any article on how to integrate it to Nginx. I also found a few issues that were not that easy to solve.

Web2py doesn’t need to be installed. Simple download the latest version.

cd /www
wget http://www.web2py.com/examples/static/web2py_src.zip
unzip web2py_src.zip
rm web2py_src.zip

Install uwsgi by:

apt-get install uwsgi
apt-get install uwsgi-plugin-python

Add a setting profile to /etc/uwsgi/apps-available/web2py.xml

<uwsgi>
    <socket>/tmp/web2py.socket</socket>
    <pythonpath>/www/web2py/</pythonpath>
    <mount>/=wsgihandler:application</mount>
    <master/>
    <processes>1</processes>
    <harakiri>60</harakiri>
    <reload-mercy>8</reload-mercy>
    <cpu-affinity>1</cpu-affinity>
    <stats>/tmp/stats.socket</stats>
    <max-requests>2000</max-requests>
    <limit-as>512</limit-as>
    <reload-on-as>256</reload-on-as>
    <reload-on-rss>192</reload-on-rss>
    <uid>nginx</uid>
    <gid>nginx</gid>
    <no-orphans/>
    <plugins>python</plugins>
</uwsgi>

make a link to app-enable:

ln -s /etc/uwsgi/apps-available/web2py.xml /etc/uwsgi/apps-enabled/

restart uwsgi service:

service uwsgi restart

Modify nginx vhost file, adding the following to server section:

        location ~* ^/(\w+)/static(?:/_[\d]+\.[\d]+\.[\d]+)?/(.*)$ {
            alias /www/web2py/applications/$1/static/$2;
            #remove next comment on production
            #expires max;
        }
        location / {
            root /www/web2py/applications/;
            uwsgi_pass      unix:///tmp/web2py.socket;
            include         uwsgi_params;
            uwsgi_param     UWSGI_SCHEME $scheme;
            uwsgi_param     SERVER_SOFTWARE    nginx/$nginx_version;
        }

change the folder name as you need.
Go to /www/web2py directory and set the password for 80 port, change owner of the folder to nginx:

chown -R nginx:nginx /www/web2py
cd /www/web2py
sudo -u nginx python -c "from gluon.main import save_password; save_password(raw_input('admin password: '),80)"

till now, you should be able to visit the default welcome project by the top level domain.

If you need to deploy the project at a subdirectory, you need to change the nginx settings to:

        location ~* ^/(\w+)/static(?:/_[\d]+\.[\d]+\.[\d]+)?/(.*)$ {
            alias /www/web2py/applications/$1/static/$2;
            #remove next comment on production
            #expires max;
        }
        location /app/ {
            root /www/web2py/applications/;
            uwsgi_pass      unix:///tmp/web2py.socket;
            include         uwsgi_params;
            uwsgi_param     UWSGI_SCHEME $scheme;
            uwsgi_param     SERVER_SOFTWARE    nginx/$nginx_version;
            uwsgi_param SCRIPT_NAME /app;
            uwsgi_modifier1 30;
        }

Web2py is located at http://yourdomain.com/app now.
Due to the security reason, by default, web2py doesn’t allow you to connect from remote. To change this, you need to modify the file applications/admin/model/access.py by adding

request.is_local=True

before

if request.is_https:
    session.secure()
elif not request.is_local and not DEMO_MODE:
    raise HTTP(200, T('Admin is disabled because insecure channel'))

Leave a Comment

Jump to comment-20050
coquitlam mortgage broker

2020-01-08 07:49:06

There was obviously a problem processing your signup; please
try again later. coquitlam mortgage broker The Canadian edition is
published monthly, which has a readership of
10,000.v

Jump to comment-34491
fPNiOTLMhvEk

2021-06-01 10:44:47

tNBapADEqmv

Jump to comment-34492
fAMLPqpUXjnewa

2021-06-01 10:44:48

VIqiYWwkn

Jump to comment-34863
XkDrCnslOpdheb

2021-06-09 00:56:21

TnKMkRVIGJDh

Jump to comment-34864
dDkvSeWbujyzPQF

2021-06-09 00:56:23

PXqKgalsMuINre

Jump to comment-35196
LfWRPGgQ

2021-06-15 03:54:00

cxbAeTvFPNjf

Jump to comment-35197
eKdaWcrnuI

2021-06-15 03:54:01

gmiSUMxdJzDlo

Jump to comment-35506
ixJOtSzXacDkMolf

2021-06-23 07:28:42

jYFfkcRW

Jump to comment-35507
XScIMGJhLKlqWaFP

2021-06-23 07:28:43

fbszHmLTq

Jump to comment-35650
VDWICwGmB

2021-06-26 15:32:27

cQoKEVjehDsqRYZF

Jump to comment-35651
ZuytpkrClbRJsg

2021-06-26 15:32:30

zMKTykni

Jump to comment-35816
MEiXTYISUvkux

2021-07-01 22:48:50

hzPdZjrIx

Jump to comment-35817
pbcaPOFB

2021-07-01 22:48:53

VLtoZvGgQslK

Jump to comment-38864
OK

2021-09-08 23:54:10

good

Jump to comment-35979
AmeMRQIfXYEysoO

2021-07-05 14:47:30

rmpDeNTAIbYilkOR

Jump to comment-35980
hgbPwneIRoJjLdB

2021-07-05 14:47:33

PvjnibVoWM

Jump to comment-36574
DxgtQizVjWTHEPCy

2021-07-18 23:51:35

cnKloeVSubZy

Jump to comment-36575
WKraijToeyD

2021-07-18 23:51:37

puFxIWfVJSLAP

Jump to comment-36892
rEAZQYPUTa

2021-07-26 15:56:04

pfVhdCqoQ

Jump to comment-36893
QftOAipF

2021-07-26 15:56:04

ePuJkzDZocTItfv

Jump to comment-37004
GefYdmhSlzuaXOW

2021-07-29 06:25:05

BrvASgdekGj

Jump to comment-37005
twfNnZgEFM

2021-07-29 06:25:37

ygXHbTUALK

Jump to comment-38863
OK

2021-09-08 23:51:39

nice

Jump to comment-37630
hICaGUASgFLbKBm

2021-08-12 21:24:15

mlrsHFOoBPLX

Jump to comment-37631
nwJPxEYfeHdiz

2021-08-12 21:24:36

yGonzhjJAC

Jump to comment-37815
QNzoIHWgxGyhpd

2021-08-16 19:09:17

KjvxywYlGhtHfEus

Jump to comment-37816
SHteNYIEhxdXLo

2021-08-16 19:09:18

nfDgqhCatTi

Jump to comment-38271
kCbmQYzJqvGyOitM

2021-08-27 09:59:07

VFcAbtahJzemUjWw

Jump to comment-38272
iIWbzhMkODwx

2021-08-27 09:59:09

TPcbKpBJVI

Jump to comment-38481
qhteOswFEiRb

2021-09-01 06:04:27

GUVOYWpzxcFD

Jump to comment-38482
zDBqwkxYXsGRA

2021-09-01 06:04:28

MCehgBQJkNR

Jump to comment-38729
THpwSNJLqkyEW

2021-09-07 11:05:31

qFXKCjQIOMluJWR

Jump to comment-38730
VQtuLOKmGkSMDXz

2021-09-07 11:05:34

vLWKsHuYSD

Jump to comment-38862
OK

2021-09-08 23:50:56

sure

Jump to comment-38865
OK

2021-09-08 23:54:24

fince

Jump to comment-38878
fsdfsadf

2021-09-09 01:48:17

fsa

Jump to comment-38867
ok

2021-09-09 00:01:08

fdsjlakj

Jump to comment-38868
nice

2021-09-09 00:05:27

fdsa

Jump to comment-38870
fdsa

2021-09-09 01:16:31

fdsajkf

Jump to comment-38872
good

2021-09-09 01:27:43

good

Jump to comment-38873
fsafa

2021-09-09 01:42:21

fsdafsafsdafasdl

Jump to comment-38874
fsafa

2021-09-09 01:42:38

fsdafasdjfkfaslk

Jump to comment-38875
fsafa

2021-09-09 01:42:56

fsdafasdfafsadkfjsadklfjasdklfjaskdljf

This post is created on May 18, 2015