I’m new to flask and the deployment procedure
I have my dash.py setup as so
server = flask.Flask(__name__)
app = dash.Dash(__name__, server=server)
and my nginx file as such
server {
listen 80;
server_name localhost;
charset utf-8;
client_max_body_size 75M;
location / {try_files $uri #yourapplication; }
location #yourapplication {
include uwsgi_params;
uwsgi_pass unix:/var/www/School-Dashboard/dash_clean.sock;
}
}
…but i’m not sure what i have to set the module parameter to in my wsgi ini file.
[uwsgi]
#application's base folder
base = /var/www/School-Dahboard
#python module to import
module = dash_clean:app #?????? WHAT DO I DO HERE
#home = %(base)/venv
pythonpath = %(base)
#socket file's location
socket = /var/www/School-Dashboard/dash_clean.sock
#permissions for the socket file
chmod-socket = 660
#location of log files
logto = /var/log/uwsgi/%n.log
I keep getting a bad gateway error because of my uwsgi file.
This is the log from uwsgi.
Starting uWSGI 2.0.17.1 (64bit) on [Mon Nov 5 12:47:42 2018] ***
compiled with version: 5.4.0 20160609 on 03 November 2018 06:53:29
os: Linux-4.15.0-36-generic #39~16.04.1-Ubuntu SMP Tue Sep 25 08:59:23 UTC 2018
nodename: xxxxxxxx
machine: x86_64
clock source: unix
detected number of CPU cores: 4
current working directory: /var/www/School-Dashboard
detected binary path: /home/concent/.local/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 31145
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/School-Dashboard/dash_clean.sock fd 3
Python version: 3.5.2 (default, Nov 23 2017, 16:37:01) [GCC 5.4.0 20160609]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x22b9330
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 72920 bytes (71 KB) for 1 cores
*** Operational MODE: single process ***
added /var/www/School-Dahboard to pythonpath.
WSGI app 0 (mountpoint='') ready in 1 seconds on interpreter 0x22b9330 pid: 20070 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (and the only) (pid: 20070, cores: 1)
So i've set up nginx as so...
server {
server_name 0.0.0.0;
listen 80;
root /home/ubuntu/school_dashboard;
client_max_body_size 200M;
include /etc/nginx/default.d/*.conf;
location /dependencies {
proxy_read_timeout 300;
proxy_connect_timeout 300;
proxy_pass http://0.0.0.0:5005;
#index wsgi.py
include uwsgi_params;
uwsgi_pass unix:/home/ubuntu/school_dashboard/dependencies/urlgen.sock;
}
}
and my uwsgi file as....
[uwsgi]
module = dash_clean:server
master = true
processes = 5
socket = dashboard.sock
chmod-socket = 660
vacuum = true
die-on-term = true
I just had to change the module parameter
The module parameter should be
module = dash:server
This is because the module is actually the name of your python file that instantiates the flask application instance. In this case it's in your dash.py. Although, in your subsequent comments you seem to reference dash_clean.py, in that case it should be:
module = dash_clean:server
The part after the module name is the name of the "callable", or the name of the variable that is the flask application.
You define it in your code example as:
server = flask.Flask(__name__)
Alternatively, you could define them seperately in the ini
module = dash
callable = server
Related
I'm new to uWSGI/gevent and I have a Python Flask Server with Flask-SocketIo sitting behind Nginx, and the server appears to freeze whenever gevent's loop engine runs. A sample output is shown below:
compiled with version: 7.5.0 on 15 April 2020 12:57:22
os: Linux-4.15.0-96-generic #97-Ubuntu SMP Wed Apr 1 03:25:46 UTC 2020
nodename: xxxxxxxxxx
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 1
current working directory: /home/admin/myapplication
detected binary path: /home/admin/myapplication/venv/bin/uwsgi
your processes number limit is 3838
your memory page size is 4096 bytes
detected max file descriptor number: 1024
- async cores set to 1000 - fd table size: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to UNIX address connect.sock fd 3
Python version: 3.6.9 (default, Nov 7 2019, 10:44:02) [GCC 8.3.0]
Python main interpreter initialized at 0x55701b9d6e40
python threads support enabled
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 21036928 bytes (20543 KB) for 1000 cores
*** Operational MODE: async ***
WSGI app 0 (mountpoint='') ready in 1 seconds on interpreter 0x55701b9d6e40 pid: 2692 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 2692)
spawned uWSGI worker 1 (pid: 2710, cores: 1000)
*** running gevent loop engine [addr:0x557019f92410] ***
At this point, the program produces no further output, despite me attempting to access the page (where I get an Error 502 Bad Gateway).
The app is run via a service file, and it appears to work fine when I run the app directly from the command line. Can anyone identify the issue in my code? (Thanks in advance)
Here is a copy of my service files:
connect.service
[Unit]
Description= xxxxxxxxxxxx
After=network.target
[Service]
User=admin
Group=www-data
WorkingDirectory=/home/admin/myapplication
Environment="PATH=/home/admin/myapplication/venv/bin"
ExecStart=/home/admin/myapplication/venv/bin/uwsgi --ini service_files/connect.ini
[Install]
WantedBy=multi-user.target
connect.ini
[uwsgi]
module = wsgi:app
master = true
gevent = 1000
http-websockets = true
socket = connect.sock
chmod-socket = 660
vacuum = true
logto = /home/admin/myapplication/service_files/logs/uwsgi/%n.log
die-on-term = true
Nginx site
server {
listen 80;
server_name subdomain.domain.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
ssl_certificate /home/admin/myapplication/service_files/connect.crt;
ssl_certificate_key /home/admin/myapplication/service_files/connect.key;
server_name subdomain.domain.com;
location / {
include uwsgi_params;
uwsgi_pass unix:///home/admin/myapplication/connect.sock;
}
location /socket.io/ {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
include uwsgi_params;
uwsgi_pass unix:///home/admin/myapplication/connect.sock;
}
}
The issue was due to a permission error (after more digging using the command sudo tail -30 /var/log/nginx/error.log)
Going to the connect.ini file and changing chmod-socket = 660 to chmod-socket = 666 solved the problem.
I have the below error with nginx uWSGI Flask application on CentOS 7 Linux:
unable to load app 0 (mountpoint='') (callable not found or import error)
I have followed Digital Ocean tut as my first time with Linux, after original Udemy tut using earlier Centos version didnt seem to work. I was able to get 'Hello world' type basic Python file to run on uwsgi and nginx following the tut, then I see several people have this error but seem different solutions. I changed permissions recursively on a parent folder above the app as I thought permissions might be source of error:
sudo chmod -R 771 www
and also giving nginx access to ?my user group? as Dig Ocean tutorial advised:
sudo usermod -a -G will nginx
chmod 710 /home/will
uwsgi.ini file is following, where /var/www/html/CON29Application1/Source/app.py is the app I want to run, not sure if module line is correct syntax:
[uwsgi]
module = Source.app
master = true
socket = /var/www/html/CON29Application1/socket.sock
chmod-socket = 777
vacuum = true
processes = 8
threads = 8
harakiri = 15
logto = /var/www/html/CON29Application1/log/%n.log
die-on-term = true
Systemd file is this at /etc/systemd/system/CON29Application1.service:
[Unit]
Description=uWSGI instance to serve CON29Application1
After=network.target
[Service]
User=will
Group=nginx
WorkingDirectory=/var/www/html/CON29Application1
Environment="PATH=/var/www/html/CON29Application1/venv/bin"
ExecStart=/var/www/html/CON29Application1/venv/bin/uwsgi --ini uwsgi.ini
[Install]
WantedBy=multi-user.target
This is default.conf file at /etc/nginx/conf.d/default.conf (server IP I blanked in this post for security reasons):
server {
listen 80;
server_name 188.xxx.xxx.xxx;
location / {
include uwsgi_params;
uwsgi_pass unix:/var/www/html/CON29Application1/socket.sock;
uwsgi_modifier1 30;
}
error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
and this is app.py file:
from flask import Flask, render_template
...
app = Flask(__name__)
app.config.from_object('Source.config')
app.secret_key = "---------------------------------"
...
And sorry as I am not that sure which files are relevant to include, so here is also the full uwsgi.log file! Thanks for any ideas:
*** Starting uWSGI 2.0.15 (64bit) on [Wed Oct 4 13:26:19 2017] ***
compiled with version: 4.8.5 20150623 (Red Hat 4.8.5-16) on 02 October 2017 21:47:33
os: Linux-3.10.0-693.el7.x86_64 #1 SMP Tue Aug 22 21:09:27 UTC 2017
nodename: CON29Application1
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 1
current working directory: /var/www/html/CON29Application1
detected binary path: /var/www/html/CON29Application1/venv/bin/uwsgi
your processes number limit is 1792
your memory page size is 4096 bytes
*** WARNING: you have enabled harakiri without post buffering. Slow upload could be rejected on post-unbuffered webservers ***
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/html/CON29Application1/socket.sock fd 3
Python version: 3.6.2 (default, Sep 27 2017, 16:30:17) [GCC 4.8.5 20150623 (Red Hat 4.8.5-16)]
Python main interpreter initialized at 0x9acbd0
python threads support enabled
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 1304064 bytes (1273 KB) for 64 cores
*** Operational MODE: preforking+threaded ***
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: 24254)
spawned uWSGI worker 1 (pid: 24259, cores: 8)
spawned uWSGI worker 2 (pid: 24260, cores: 8)
spawned uWSGI worker 3 (pid: 24261, cores: 8)
spawned uWSGI worker 4 (pid: 24262, cores: 8)
spawned uWSGI worker 5 (pid: 24263, cores: 8)
spawned uWSGI worker 6 (pid: 24264, cores: 8)
spawned uWSGI worker 7 (pid: 24265, cores: 8)
spawned uWSGI worker 8 (pid: 24266, cores: 8)
I have django app that is running using the following uwsgi configuration in redhat 7.3:
[uwsgi]
project = helloworld
base = %d
chdir=%(base)
module=helloworld.wsgi:application
plugins = router_redirect
route-if = equal:${HTTPS};on addheader:Strict-Transport-Security: max-age=31536000
master = true
processes = 1
enable-threads = true
threads = 1
max-requests = 2000
shared-socket = 0.0.0.0:443
https = =0,cert/hello.crt,cert/hello.key,HIGH
pidfile = hello_uwsgi.pid
vacuum = true
die-on-term = true
However, when I run it on Ubuntu 16.04.1 LTS, I got the following error:
your processes number limit is 31283
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)
Python version: 3.5.2 (default, Nov 17 2016, 17:05:23) [GCC 5.4.0 20160609]
Python main interpreter initialized at 0x1dfabe0
python threads support enabled
The -s/--socket option is missing and stdin is not a socket.
VACUUM: pidfile removed.
Does the error means that uwsgi fail to bind the port?
Is there a special way of using "shared-socket" in ubuntu?
I need to have this running on both port 443 and 8443. I have tried the above configuration for both port 443 and 8443 without success.
Thanks in advance.
I got this to work in ubuntu by reinstalling the python 3.5.2 from source.
I am guessing that there is some issue/incompatibility installing python 3.5.2 using apt-get.
I am trying to set up nginx to work with uwsgi, I am on Arch Linux. I have /etc/uwsgi/emperor.ini and /etc/uwsgi/vassals/myapp.ini. My emperor.ini looks like:
[uwsgi]
emperor = /etc/uwsgi/vassals
emperor-pidfile = /run/uwsgi/uwsgi.pid
uid = http
gid = http
logto = /var/log/uwsgi/uwsgi.log
myapp.ini
[uwsgi]
chdir = /srv/http/myapp/src/
wsgi-file = run.py
callable = app
processes = 4
threads = 2
offload-threads = 2
stats = 127.0.0.1:9191
max-requests = 5000
master = True
vacuum = True
socket = 127.0.0.1:3031
enable-threads = true
harakiri = 60
logto = /var/log/uwsgi/myapp.log
uwsgi.service [for systemd]
[Unit]
Description=uWSGI Emperor
After=syslog.target
[Service]
PIDFile=/run/uwsgi/uwsgi.pid
ExecStartPre=/bin/mkdir -p /run/uwsgi
ExecStartPre=/bin/chown http:http /run/uwsgi
ExecStart=/usr/bin/uwsgi --ini /etc/uwsgi/emperor.ini
Restart=always
Type=notify
StandardError=syslog
NotifyAccess=main
[Install]
WantedBy=multi-user.target
Yet when the uwsgi.service runs I get:
uwsgi.service - uWSGI Emperor
Loaded: loaded (/etc/systemd/system/uwsgi.service; disabled)
Active: active (running) since Sun 2014-02-02 04:37:04 PST; 34min ago
Process: 31537 ExecStartPre=/bin/chown http:http /run/uwsgi (code=exited, status=0/SUCCESS)
Process: 31535 ExecStartPre=/bin/mkdir -p /run/uwsgi (code=exited, status=0/SUCCESS)
Main PID: 31540 (uwsgi)
Status: "The Emperor is governing 0 vassals"
CGroup: /system.slice/uwsgi.service
ââ31540 /usr/bin/uwsgi --ini /etc/uwsgi/emperor.ini
Feb 02 04:37:04 MyMachine uwsgi[31540]: [uWSGI] getting INI configuration from /etc/uwsgi/emperor.ini
Feb 02 04:37:04 MyMachine systemd[1]: Started uWSGI Emperor.
That bit right there? "The Emperor is governing 0 vassals" for some reason it will not look at the myapp.ini in the vassal directory. This is what I get in a command line "log":
*** Starting uWSGI 2.0 (64bit) on [Sun Feb 2 05:27:37 2014] ***
compiled with version: 4.8.2 20131219 (prerelease) on 09 January 2014 11:43:55
os: Linux-3.12.7-2-ARCH #1 SMP PREEMPT Sun Jan 12 13:09:09 CET 2014
nodename: MyMachine
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 2
current working directory: /home/me
detected binary path: /usr/bin/uwsgi
your processes number limit is 26743
your memory page size is 4096 bytes
*** WARNING: you have enabled harakiri without post buffering. Slow upload could be rejected on post-unbuffered webservers ***
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 TCP address 127.0.0.1:3031 fd 3
Python version: 2.7.6 (default, Nov 26 2013, 12:52:49) [GCC 4.8.2]
Python main interpreter initialized at 0xcfd340
python threads support enabled
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 415280 bytes (405 KB) for 8 cores
*** Operational MODE: preforking+threaded ***
WSGI app 0 (mountpoint='') ready in 2 seconds on interpreter 0xcfd340 pid: 32089 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 32089)
spawned uWSGI worker 1 (pid: 32092, cores: 2)
spawned 2 offload threads for uWSGI worker 1
spawned uWSGI worker 2 (pid: 32095, cores: 2)
spawned uWSGI worker 3 (pid: 32097, cores: 2)
spawned 2 offload threads for uWSGI worker 3
spawned uWSGI worker 4 (pid: 32100, cores: 2)
spawned 2 offload threads for uWSGI worker 2
spawned 2 offload threads for uWSGI worker 4
I cannot seem to get uwsgi to run see its vassals no matter what I do. Thanks.
EDIT
OK so I decided to go back to the command line so I don't have to deal with log and pid permission errors and I noticed something strange. When I make write out uwsgi --ini /etc/uwsgi/emperor.ini the entire thing works, I can access the site through nginx, beautiful, but I saw this in the console output:
*** Starting uWSGI 2.0 (64bit) on [Sun Feb 2 15:19:43 2014] ***
compiled with version: 4.8.2 20131219 (prerelease) on 09 January 2014 11:43:55
os: Linux-3.12.9-2-ARCH #1 SMP PREEMPT Fri Jan 31 10:22:54 CET 2014
nodename: MyMachine
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 2
current working directory: /home/me
detected binary path: /usr/bin/uwsgi
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 26743
your memory page size is 4096 bytes
detected max file descriptor number: 1024
*** starting uWSGI Emperor ***
*** has_emperor mode detected (fd: 5) ***
[uWSGI] getting INI configuration from /etc/uwsgi/emperor.ini
*** Starting uWSGI 2.0 (64bit) on [Sun Feb 2 15:19:43 2014] ***
compiled with version: 4.8.2 20131219 (prerelease) on 09 January 2014 11:43:55
os: Linux-3.12.9-2-ARCH #1 SMP PREEMPT Fri Jan 31 10:22:54 CET 2014
nodename: MyMachine
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 2
current working directory: /home/me
detected binary path: /usr/bin/uwsgi
your processes number limit is 26743
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)
*** starting uWSGI sub-Emperor ***
Python version: 2.7.6 (default, Nov 26 2013, 12:52:49) [GCC 4.8.2]
*** has_emperor mode detected (fd: 7) ***
[uWSGI] getting INI configuration from myapp.ini
*** Starting uWSGI 2.0 (64bit) on [Sun Feb 2 15:19:43 2014] ***
compiled with version: 4.8.2 20131219 (prerelease) on 09 January 2014 11:43:55
os: Linux-3.12.9-2-ARCH #1 SMP PREEMPT Fri Jan 31 10:22:54 CET 2014
nodename: MyMachine
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 2
current working directory: /etc/uwsgi/vassals
detected binary path: /usr/bin/uwsgi
your processes number limit is 26743
your memory page size is 4096 bytes
*** WARNING: you have enabled harakiri without post buffering. Slow upload could be rejected on post-unbuffered webservers ***
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 TCP address 127.0.0.1:3031 fd 3
Python version: 2.7.6 (default, Nov 26 2013, 12:52:49) [GCC 4.8.2]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x2403ab0
your mercy for graceful operations on workers is 60 seconds
*** Operational MODE: no-workers ***
spawned uWSGI master process (pid: 1640)
Sun Feb 2 15:19:43 2014 - [emperor] vassal /etc/uwsgi/emperor.ini has been spawned
Python main interpreter initialized at 0x17682a0
python threads support enabled
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 415280 bytes (405 KB) for 8 cores
*** Operational MODE: preforking+threaded ***
WSGI app 0 (mountpoint='') ready in 2 seconds on interpreter 0x17682a0 pid: 1642 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 1642)
Sun Feb 2 15:19:45 2014 - [emperor] vassal myapp.ini has been spawned
spawned uWSGI worker 1 (pid: 1645, cores: 2)
spawned 2 offload threads for uWSGI worker 1
spawned uWSGI worker 2 (pid: 1648, cores: 2)
Sun Feb 2 15:19:45 2014 - [emperor] vassal myapp.ini is ready to accept requests
spawned 2 offload threads for uWSGI worker 2
spawned uWSGI worker 3 (pid: 1651, cores: 2)
spawned 2 offload threads for uWSGI worker 3
spawned uWSGI worker 4 (pid: 1657, cores: 2)
*** Stats server enabled on 127.0.0.1:9191 fd: 16 ***
spawned 2 offload threads for uWSGI worker 4
[pid: 1648|app: 0|req: 1/1] 192.168.1.156 () {40 vars in 795 bytes} [Sun Feb 2 15:20:40 2014] GET /articles => generated 2943 bytes in 164 msecs (HTTP/1.1 200) 3 headers in 283 bytes (1 switches on core 0)
announcing my loyalty to the Emperor...
Sun Feb 2 15:20:40 2014 - [emperor] vassal myapp.ini is now loyal
[pid: 1657|app: 0|req: 1/2] 192.168.1.156 () {40 vars in 792 bytes} [Sun Feb 2 15:20:41 2014] GET /index => generated 3216 bytes in 184 msecs (HTTP/1.1 200) 3 headers in 283 bytes (1 switches on core 0)
announcing my loyalty to the Emperor...
Sun Feb 2 15:20:42 2014 - [emperor] vassal myapp.ini is now loyal
I started noticing some odd ball behavior in the output. I finally came down to this configuration which let's me see my site.
emperor.ini
[uwsgi]
emperor = /etc/uwsgi/vassals
master = true
#gid = http
#uid = http
I commented out the gid and uid because with them there I get a bad gateway response when I try to connect to my website, it warns me about it in the log uWSGI running as root, you can use --uid/--gid/--chroot options but I am not sure what to do about it.
myapp.ini
[uwsgi]
chdir = /srv/http/myapp/src/
wsgi-file = run.py
callable = app
processes = 4
threads = 2
offload-threads = 2
stats = 127.0.0.1:9191
max-requests = 5000
master = true
vacuum = true
socket = 127.0.0.1:3031
harakiri = 60
uwsgi.service
[Unit]
Description=uWSGI Emperor
After=syslog.target
[Service]
ExecStart=/usr/bin/uwsgi --ini /etc/uwsgi/emperor.ini --enable-threads
Restart=always
KillSignal=SIGQUIT
Type=notify
StandardError=syslog
NotifyAccess=main
[Install]
WantedBy=multi-user.target
No idea what to do about it running as root.
create a vassals in /etc/uwsgi/vassals/
I'm trying to roll out a pyramid app to a production site.
As of now, I've created the env file where the app is placed in out of the public_html, something like below:
[~/env] $
So I've typed
$ ../bin/pserve production.ini,
However, when I access www.mydomain.com, it is still showing the index.html. How should I resolve this?
I'm using a CentOS 64bit + Apache + mod_wsgi.
Settings are as followed:
Apache/2.2.24 (Unix)
mod_ssl/2.2.24
OpenSSL/1.0.0-fips
mod_wsgi/3.3
Python/2.6.6
mod_auth_passthrough/2.1
mod_bwlimited/1.4
FrontPage/5.0.2.2635 configured -- resuming normal operations
In my production.ini file, it is as followed
[app:main]
use = egg:ECommerce
reload_templates = false
debug_authorization = false
debug_notfound = false
debug_routematch = false
debug_templates = false
default_locale_name = en
mongodb.url = mongodb://my.ip.address
mongodb.db_name = mycart_demo
[filter:weberror]
use = egg:WebError#error_catcher
debug = false
;error_log =
;show_exceptions_in_wsgi_errors = true
;smtp_server = localhost
;error_email = janitor#example.com
;smtp_username = janitor
;smtp_password = "janitor's password"
;from_address = paste#localhost
;error_subject_prefix = "Pyramid Error"
;smtp_use_tls =
;error_message =
#[pipeline:main]
#pipeline =
# weberror
# ECommerce
[server:main]
use = egg:waitress#main
host = 0.0.0.0
port = 8080
# Begin logging configuration
[loggers]
keys = root, ecommerce
[handlers]
keys = console
[formatters]
keys = generic
[logger_root]
level = WARN
handlers = console
[logger_ecommerce]
level = WARN
handlers =
qualname = ecommerce
[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic
[formatter_generic]
format = %(asctime)s %(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s
# End logging configuration
I've managed to roll out on a production site, however, now, it's showing a 500 internal server error...
In the apache error_log, it's showing:
[Sun Apr 07 23:17:47 2013] [alert] [client <ip_address>]
/home/vretnet9/public_html/.htaccess: WSGIScriptAlias not allowed here
So I went ahead to take a look at .htaccess
.htaccess
Options +ExecCGI
AddHandler cgi-script .cgi
AddHandler wsgi-script .wsgi
WSGIScriptAlias ECommerce /home/vretnet9/modwsgi/env/pyramid.wsgi
WSGIDaemonProcess root processes=5 threads=1 display-name=%{GROUP}
WSGIProcessGroup root
WSGIApplicationGroup %{GLOBAL}
I don't know if it should actually be calling the .htaccess or if the scriptalias should be the same as the one in my .conf which is located in
/usr/local/apache/conf/userdata/std/1/$user/$domain/modwsgi.conf
the contents of modwsgi.conf is as followed:
WSGIApplicationGroup %{GLOBAL}
WSGIPassAuthorization On
WSGIDaemonProcess pyramid user=vretnet9 group=vretnet9 threads=4 \
python-path=/home/vretnet9/modwsgi/env/lib/python3.3/site-packages
WSGIScriptAlias /ECommerce /home/vretnet9/modwsgi/env/pyramid.wsgi
<Directory /home/vretnet9/modwsgi/env>
WSGIProcessGroup pyramid
Order allow,deny
Allow from all
</Directory>
EDIT
In the apache error_log, the following is being recorded:
[Mon Apr 08 02:17:22 2013] [error] Traceback (most recent call last):
[Mon Apr 08 02:17:22 2013] [error] File
"/home/vretnet9/modwsgi/env/pyramid.wsgi", line 5, in <module>
[Mon Apr 08 02:17:22 2013] [error] from pyramid.paster import get_app,
setup_logging
[Mon Apr 08 02:17:22 2013] [error] File "/home/vretnet9/modwsgi/env/
lib/python3.3/site-packages/pyramid/paster.py", line 1, in <module>
[Mon Apr 08 02:17:22 2013] [error] import os
[Mon Apr 08 02:17:22 2013] [error] ImportError: No module named os
EDIT #2
This is my result when running in shell:
[~/modwsgi/env]# python
Python 3.3.0 (default, Mar 27 2013, 09:31:49)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> print (os.getcwd())
/home/vretnet9/modwsgi/env
That is not how you will put a pyramid project into production using mod_wsgi + Apache. I recommend reading The official documentation
When you run ../bin/pserve production.ini it starts a paste HTTP server at port 8080 (defined in production.ini)
Ideally you will want to install pyramid in a fresh virtualenvironment and then configure mod_wsgi to use that instance of python. You will have to add a .wsgi script to your project and configure mod_wsgi to run that script on Apache startup.
EDIT
The ScriptAlias (and all related parts) should be in your modwsgi.conf (Make sure you import modwsgi.conf in your actual apache conf).
In that file you should define your PYTHONPATH and PYTHONHOME( esp. If you have a virtualenv) and the rest of the stuff you have already defined (WSGIApplicationGroup, WSGIScriptAlias etc.)
IMPORTANT - Make sure your apache user (apache) has read-execute permissions to the .wsgi script all the way. This means even your /home directory should be accessible to apache.
I would recommend creatijg a seaparate directory (say /opt/proj) for hosting the app and another (say /opt/env for the environment).
Here's how my pyramid.conf looks. I have Python 2.6 and keep my project (only the static things like css,images,js, and the .wsgi script) at /opt/save_project. My virtualenv is /opt/pyra
WSGIPythonHome /opt/pyra
WSGIPythonPath /opt/pyra/lib/python2.6
<VirtualHost 31.1.1.22:8005>
DocumentRoot /opt/save_project
WSGIApplicationGroup %{GLOBAL}
WSGIPassAuthorization On
WSGIProcessGroup %{GLOBAL}
WSGIDaemonProcess pyramid user=apache group=apache \
python-path=/opt/pyra/lib/python2.6
WSGIScriptAlias / /opt/save_project/pyramid.wsgi
# Get the static and favicon.ico pages working by properly aliasing them
Alias /favicon.ico /opt/save_project/static/images/favicon.ico
Alias /static /opt/save_project/static
<Directory /opt/save_project>
AllowOverride all
Options -MultiViews
</Directory>
</VirtualHost>
You may see mod_wsgi docs for more information