Web2py with ngix

223 views
Skip to first unread message

J Boggy

unread,
Dec 7, 2016, 11:53:58 PM12/7/16
to web2py-users
Web2py with ngix start work well.
But when i start uwsgi
it show uwsgi.service not found error.
If i need to create service i don't know how to create.
I follow this way
https://www.digitalocean.com/community/tutorials/how-to-deploy-web2py-python-applications-with-uwsgi-and-nginx-on-ubuntu-14-04

Mirek Zvolský

unread,
Dec 8, 2016, 6:56:22 AM12/8/16
to web...@googlegroups.com
On my working machine (Debian 8 Testing (systemd), nginx)
I have installed with the script

but there was some problem or some missing code which I have found somewhere here in user group.

I am not sure if last version of the script at github.com/web2py/web2py works,

but maybe my files could help you:

-rw-r--r-- root root /etc/init/uwsgi-emperor.conf

description "uWSGI Emperor"
start on runlevel [2345]
stop on runlevel [06]
##
#remove the comments in the next section to enable static file compression for the welcome app
#in that case, turn on gzip_static on; on /etc/nginx/nginx.conf
##
#pre-start script
#    python /home/www-data/web2py/web2py.py -S welcome -R scripts/zip_static_files.py
#    chown -R www-data:www-data /home/www-data/web2py/*
#end script
respawn
exec uwsgi --master --die-on-term --emperor /etc/uwsgi --logto /var/log/uwsgi/uwsgi.log

-rw-r--r-- root root /etc/uwsgi/web2py.ini

[uwsgi]

socket = /tmp/web2py.socket
pythonpath = /home/www-data/web2py/
mount = /=wsgihandler:application
processes = 4
master = true
harakiri = 60
reload-mercy = 8
cpu-affinity = 1
stats = /tmp/stats.socket
max-requests = 2000
limit-as = 512
reload-on-as = 256
reload-on-rss = 192
uid = www-data
gid = www-data
touch-reload = /home/www-data/web2py/routes.py
cron = 0 0 -1 -1 -1 python /home/www-data/web2py/web2py.py -Q -S welcome -M -R scripts/sessions2trash.py -A -o
no-orphans = true

Previous works and I made no my own changes inside. It is just from the Web2py nginx/ubuntu script and from some post in this user group.

I control the service so:
systemctl start emperor.uwsgi     # stop,restart,status,...


Mirek Zvolský

unread,
Dec 8, 2016, 7:04:41 AM12/8/16
to web...@googlegroups.com
And this is the third file:

-rw-r--r-- root root /etc/systemd/system/emperor.uwsgi.service

[Unit]
Description = uWSGI Emperor
After = syslog.target

[Service]
ExecStart = /usr/local/bin/uwsgi --ini /etc/uwsgi/web2py.ini
RuntimeDirectory = uwsgi
Restart = always
KillSignal = SIGQUIT
Type = notify
StandardError = syslog
NotifyAccess = all

[Install]
WantedBy = multi-user.target

... I hope it is complete now...

Mirek Zvolský

unread,
Dec 8, 2016, 7:18:19 AM12/8/16
to web2py-users
And here is the version of script that I have used (I hope so) to install on my machine.

So if you decide use the installation script setup-web2py-nginx-uwsgi-ubuntu.sh
maybe you could try the version from current trunk github.com/web2py/web2py
and as second one you can try this version:

#!/bin/bash
echo 'setup-web2py-nginx-uwsgi-ubuntu-precise.sh'
echo 'Requires Ubuntu > 12.04 or Debian >= 8 and installs Nginx + uWSGI + Web2py'
# Check if user has root privileges
if [[ $EUID -ne 0 ]]; then
   echo "You must run the script as root or using sudo"
   exit 1
fi
# parse command line arguments
nopassword=0
nocertificate=0
while [ "$#" -gt 0 ]; do
  case "$1" in
    --no-password) nopassword=1; shift 1;;
    --no-certificate) nocertificate=1; shift 1;;
  esac
done
# Get Web2py Admin Password
if [ "$nopassword" -eq 0 ]
then
  echo -e "Web2py Admin Password: \c "
  read  PW
fi
# Upgrade and install needed software
apt-get update
apt-get -y upgrade
apt-get autoremove
apt-get autoclean
apt-get -y install nginx-full
apt-get -y install build-essential python-dev libxml2-dev python-pip unzip
pip install setuptools --no-use-wheel --upgrade
PIPPATH=`which pip`
$PIPPATH install --upgrade uwsgi
# Create common nginx sections
mkdir /etc/nginx/conf.d/web2py
echo '
gzip_static on;
gzip_http_version   1.1;
gzip_proxied        expired no-cache no-store private auth;
gzip_disable        "MSIE [1-6]\.";
gzip_vary           on;
' > /etc/nginx/conf.d/web2py/gzip_static.conf
echo '
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
' > /etc/nginx/conf.d/web2py/gzip.conf
# Create configuration file /etc/nginx/sites-available/web2py
echo 'server {
        listen          80;
        server_name     $hostname;
        ###to enable correct use of response.static_version
        location ~* ^/(\w+)/static(?:/_[\d]+\.[\d]+\.[\d]+)?/(.*)$ {
            alias /home/www-data/web2py/applications/$1/static/$2;
            expires max;
            ### if you want to use pre-gzipped static files (recommended)
            ### check scripts/zip_static_files.py and remove the comments
            # include /etc/nginx/conf.d/web2py/gzip_static.conf;
        }
        ###

        ###if you use something like myapp = dict(languages=['en', 'it', 'jp'], default_language='en') in your routes.py
        #location ~* ^/(\w+)/(en|it|jp)/static/(.*)$ {
        #    alias /home/www-data/web2py/applications/$1/;
        #    try_files static/$2/$3 static/$3 =404;
        #}
        ###
        
        location / {
            #uwsgi_pass      127.0.0.1:9001;
            uwsgi_pass      unix:///tmp/web2py.socket;
            include         uwsgi_params;
            uwsgi_param     UWSGI_SCHEME $scheme;
            uwsgi_param     SERVER_SOFTWARE    nginx/$nginx_version;

            ###remove the comments to turn on if you want gzip compression of your pages
            # include /etc/nginx/conf.d/web2py/gzip.conf;
            ### end gzip section

            ### remove the comments if you use uploads (max 10 MB)
            #client_max_body_size 10m;
            ###
        }
}
server {
        listen 443 default_server ssl;
        server_name     $hostname;
        ssl_certificate         /etc/nginx/ssl/web2py.crt;
        ssl_certificate_key     /etc/nginx/ssl/web2py.key;
        ssl_prefer_server_ciphers on;
        ssl_session_cache shared:SSL:10m;
        ssl_session_timeout 10m;
        ssl_ciphers ECDHE-RSA-AES256-SHA:DHE-RSA-AES256-SHA:DHE-DSS-AES256-SHA:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        keepalive_timeout    70;
        location / {
            #uwsgi_pass      127.0.0.1:9001;
            uwsgi_pass      unix:///tmp/web2py.socket;
            include         uwsgi_params;
            uwsgi_param     UWSGI_SCHEME $scheme;
            uwsgi_param     SERVER_SOFTWARE    nginx/$nginx_version;
            ###remove the comments to turn on if you want gzip compression of your pages
            # include /etc/nginx/conf.d/web2py/gzip.conf;
            ### end gzip section
            ### remove the comments if you want to enable uploads (max 10 MB)
            #client_max_body_size 10m;
            ###
        }
        ###to enable correct use of response.static_version
        location ~* ^/(\w+)/static(?:/_[\d]+\.[\d]+\.[\d]+)?/(.*)$ {
            alias /home/www-data/web2py/applications/$1/static/$2;
            expires max;
            ### if you want to use pre-gzipped static files (recommended)
            ### check scripts/zip_static_files.py and remove the comments
            # include /etc/nginx/conf.d/web2py/gzip_static.conf;
        }
        ###

}' >/etc/nginx/sites-available/web2py

ln -s /etc/nginx/sites-available/web2py /etc/nginx/sites-enabled/web2py
rm /etc/nginx/sites-enabled/default
mkdir /etc/nginx/ssl
cd /etc/nginx/ssl
if [ "$nocertificate" -eq 0 ]
then
  openssl genrsa 1024 > web2py.key
  chmod 400 web2py.key
  openssl req -new -x509 -nodes -sha1 -days 1780 -key web2py.key > web2py.crt
  openssl x509 -noout -fingerprint -text < web2py.crt > web2py.info
fi
# Prepare folders for uwsgi
sudo mkdir /etc/uwsgi
sudo mkdir /var/log/uwsgi
sudo mkdir /etc/systemd
sudo mkdir /etc/systemd/system

#uWSGI Emperor
echo '[Unit]
Description = uWSGI Emperor
After = syslog.target

[Service]
ExecStart = /usr/local/bin/uwsgi --ini /etc/uwsgi/web2py.ini
RuntimeDirectory = uwsgi
Restart = always
KillSignal = SIGQUIT
Type = notify
StandardError = syslog
NotifyAccess = all

[Install]
WantedBy = multi-user.target
' > /etc/systemd/system/emperor.uwsgi.service

# Create configuration file /etc/uwsgi/web2py.ini
echo '[uwsgi]

socket = /tmp/web2py.socket
pythonpath = /home/www-data/web2py/
mount = /=wsgihandler:application
processes = 4
master = true
harakiri = 60
reload-mercy = 8
cpu-affinity = 1
stats = /tmp/stats.socket
max-requests = 2000
limit-as = 512
reload-on-as = 256
reload-on-rss = 192
uid = www-data
gid = www-data
touch-reload = /home/www-data/web2py/routes.py
cron = 0 0 -1 -1 -1 python /home/www-data/web2py/web2py.py -Q -S welcome -M -R scripts/sessions2trash.py -A -o
no-orphans = true
' >/etc/uwsgi/web2py.ini

#Create a configuration file for uwsgi in emperor-mode
#for Upstart in /etc/init/uwsgi-emperor.conf
echo '# Emperor uWSGI script

description "uWSGI Emperor"
start on runlevel [2345]
stop on runlevel [06]
##
#remove the comments in the next section to enable static file compression for the welcome app
#in that case, turn on gzip_static on; on /etc/nginx/nginx.conf
##
#pre-start script
#    python /home/www-data/web2py/web2py.py -S welcome -R scripts/zip_static_files.py
#    chown -R www-data:www-data /home/www-data/web2py/*
#end script
respawn
exec uwsgi --master --die-on-term --emperor /etc/uwsgi --logto /var/log/uwsgi/uwsgi.log
' > /etc/init/uwsgi-emperor.conf
# Install Web2py
mkdir /home/www-data
cd /home/www-data
unzip web2py_src.zip
mv web2py/handlers/wsgihandler.py web2py/wsgihandler.py
rm web2py_src.zip
chown -R www-data:www-data web2py
cd /home/www-data/web2py
if [ "$nopassword" -eq 0 ]
then
   sudo -u www-data python -c "from gluon.main import save_password; save_password('$PW',443)"
fi

sudo systemctl restart nginx
sudo systemctl restart emperor.uwsgi

echo <<EOF
you can stop uwsgi and nginx with

  sudo systemctl stop nginx
  sudo systemctl stop emperor.uwsgi
 
and start it with

  sudo systemctl start nginx
  sudo systemctl start emperor.uwsgi

EOF






On Thursday, 8 December 2016 05:53:58 UTC+1, J Boggy wrote:

Mirek Zvolský

unread,
Dec 8, 2016, 7:27:15 AM12/8/16
to web2py-users
One thing more....
In my opinion the service is controlled without ".service" in name.

systemctl start emperor.uwsgi    (if /etc/systemd/system/emperor.uwsgi.service used)

systemctl start uwsgi    (if the name is /etc/systemd/system/uwsgi.service as (maybe) in your 'digitalocean' article)





On Thursday, 8 December 2016 05:53:58 UTC+1, J Boggy wrote:

Richard Vézina

unread,
Dec 8, 2016, 10:08:32 AM12/8/16
to web2py-users
Hello Mirek,

Your contribution is pretty much appreciate, but it would make more sens that you submit your improvements as a PR over github and then point other users over you fork or the PR pending acceptation our your commit once PR accepted...

Thanks for your help

Richard

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mirek Zvolský

unread,
Dec 8, 2016, 10:29:46 AM12/8/16
to web2py-users
Hi Richard.

I'm beginner with Linux (upgrade from Windows to Linux was one of best steps in my professional life!).
However at this time it is for me not good idea to write bash scripts for some complex product.

In fact I made PR in this case (when I have added something from other post in this user group into the Web2py nginx/ubuntu script).
It was not accepted, but maybe the team has implemented/reimplemented the changes into the framework full or partially.

But I am not sure about this (and haven't time to test it).
This is the reason why I have written:
  - give first opportunity to the script from framework (github web2py/web2py),
  - if it fails, then (maybe) my version could work.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.

Richard Vézina

unread,
Dec 8, 2016, 12:01:46 PM12/8/16
to web2py-users
No problem...

You maybe could post diff of your change, it would greatly help to understand what you change.

Maybe it get rejected because it was applying for Debian only?

Anyway thanks for your contribution, I just want to point you in the rigth direction to improve chance your work didn't get lost on the list as it happen sometimes.

:)

Richard



To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscribe@googlegroups.com.

wish...@gmail.com

unread,
Dec 8, 2016, 5:03:37 PM12/8/16
to web2py-users
I just posted an issue with uwsgi and setup-web2py-nginx-uwsgi-ubuntu.sh to the mailing list ( https://groups.google.com/forum/#!topic/web2py/U_GTzcdXdKE )
This might possible be related..


On Thursday, 8 December 2016 05:53:58 UTC+1, J Boggy wrote:

Richard Vézina

unread,
Dec 8, 2016, 8:32:58 PM12/8/16
to web2py-users
Could you link issue here?


Richard

--

Mirek Zvolský

unread,
Dec 9, 2016, 9:00:38 AM12/9/16
to web2py-users
Thanks, Richard.
I have my Web2py fork and I will send PR in the future if I will know, what to improve.

I have just now compared current Web2py script --vs-- version of script I have used (it was in my fork, but I have reinstalled without it) --vs-- configuration files on my well working server,

and I see all of them have all 3 configuration files (/etc/init/.., /etc/uwsgi/.., /etc/systemd/system/..)
and these files are identical.
So I think the installation with the nginx/ubuntu script (from trunk) will work.

There was some problem in OLD history (2015?):
/etc/uwsgi/web2py.ini was missing (web2py 2.13.4) + there was a missing code in /etc/systemd/system/emperor.uwsgi.service


I think today is all ok with current stable and with trunk too.

Richard Vézina

unread,
Dec 9, 2016, 10:46:22 AM12/9/16
to web2py-users
Yes, there were a lot of changes related to systemd as the way to init deamon as change a lot... Despite all the criticism about systemd, I found it a lot more simpler to write init (just a few lines of code) compare to the old /etc/init.d/ bash script file...

Regards

Richard

 

To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscribe@googlegroups.com.

wish...@gmail.com

unread,
Dec 9, 2016, 10:58:29 AM12/9/16
to web2py-users
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.

J Boggy

unread,
Dec 10, 2016, 2:21:21 AM12/10/16
to web2py-users
thz i have been solved.
Now other error is i cannot import some module althougn i have been installed and tested on python. But in web2py controller i can't import module

Richard Vézina

unread,
Dec 12, 2016, 1:17:48 PM12/12/16
to web2py-users
Hello Boggy,

Are you installing web2py over your own server or or cloud service?

If it your own server can you details what you have done so far, are you trying to install web2py by hand or you use one the scripts provided with web2py?

Richard

On Sat, Dec 10, 2016 at 2:21 AM, J Boggy <jbog...@gmail.com> wrote:
thz i have been solved.
Now other error is i cannot import some module althougn i have been installed and tested on python. But in web2py controller i can't import module
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages