I try to host my webpage in a server with OS Ubuntu 16.04 and Python2/Flask/uwsgi(emperor).
The configuration of the emperor in /etc/uwsgi/emperor.ini is as follow:
[uwsgi]
emperor = /etc/uwsgi/vassals
uid = www-data
gid = www-data
and the emperor service can be launched normally, since results of sudo systemctl status emperor.uwsgi shows the uwsgi ini file is loaded normally:
?.emperor.uwsgi.service - uWSGI Emperor
Loaded: loaded (/etc/systemd/system/emperor.uwsgi.service; enabled; vendor preset: enable
Active: active (running) since Sun 2017-01-08 00:18:03 EST; 43min ago
Main PID: 150 (uwsgi)
Status: "The Emperor is governing 1 vassals"
CGroup: /system.slice/emperor.uwsgi.service
?..150 /usr/local/bin/uwsgi --ini /etc/uwsgi/emperor.ini
?..160 /usr/local/bin/uwsgi --ini proxy.ini
?..172 /usr/local/bin/uwsgi --ini proxy.ini
Jan 08 00:18:03 localhost uwsgi[150]: *** WARNING: you are running uWSGI without its master
Jan 08 00:18:03 localhost uwsgi[150]: your processes number limit is 579533
Jan 08 00:18:03 localhost uwsgi[150]: your memory page size is 4096 bytes
Jan 08 00:18:03 localhost uwsgi[150]: detected max file descriptor number: 1024
Jan 08 00:18:03 localhost uwsgi[150]: * ** starting uWSGI Emperor ***
Jan 08 00:18:03 localhost systemd[1]: Started uWSGI Emperor.
Jan 08 00:18:03 localhost uwsgi[150]: * ** has_emperor mode detected (fd: 7) ***
Jan 08 00:18:03 localhost uwsgi[150]: [uWSGI] getting INI configuration from proxy.ini
Jan 08 00:18:03 localhost uwsgi[150]: Sun Jan 8 00:18:03 2017 - [emperor] vassal proxy.ini
Jan 08 00:18:03 localhost uwsgi[150]: Sun Jan 8 00:18:03 2017 - [emperor] vassal proxy.ini
The directory of the webpage is /var/www/proxy and the uwsgi ini file is /var/www/proxy/proxy.ini as follow:
[uwsgi]
base = /var/www/proxy
app = index
module = %(app)
home = %(base)
pythonpath = %(base)
socket = /var/www/proxy/%n.sock
chmod-socket = 666
callable = app
logto = /var/log/uwsgi/%n.log
no-site=true
The nginx configuration file /etc/nginx/sites-enabled/proxy:
upstream flask {
server unix:///var/www/proxy/proxy.sock;
}
# Default server configuration
server {
listen 80;
server_name proxy.foool.net;
charset utf-8;
location / {
uwsgi_pass flask;
include uwsgi_params;
}
}
However, it returns a Internal Server Error when opening the webpage, and the log file /var/log/uwsgi/proxy.log shows a ImportError: No module named os Error. see more details:
machine: x86_64
compiled with version: 5.4.0 20160609 on 07 January 2017 23:28:17
os: Linux-2.6.32-042stab113.21 #1 SMP Wed Mar 23 11:05:25 MSK 2016
nodename: localhost
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 1
current working directory: /etc/uwsgi/vassals
detected binary path: /usr/local/bin/uwsgi
your processes number limit is 579533
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to UNIX address /var/www/proxy/proxy.sock fd 3
Python version: 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609]
Set PythonHome to /var/www/proxy
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x1fb4bf0
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 145520 bytes (142 KB) for 1 cores
*** Operational MODE: single process ***
added /var/www/proxy/ to pythonpath.
Traceback (most recent call last):
File "/var/www/proxy/index.py", line 2, in <module>
import os
ImportError: No module named os
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 160)
spawned uWSGI worker 1 (pid: 172, cores: 1)
So, How can I solve this ImportError problem? My default python is python2.7.12, and pip3 is not installed.
Update:
Bypass the the systemctl and emperor, my project is running with the command uwsgi --socket 0.0.0.0:5000 --protocol=http -w index:application, so I think the uwsgi is fine.