Serving a Pyramid Application with UWSGI and NGINX

I am new to NGINX, uWSGI and Pyramid and I am trying to use a Pyramid application through uWSGI using nginx as a reverse proxy. I am really stuck at the moment and I hope someone can make some suggestions on how to solve this. If you can explain a little what might be going on, that would be helpful too, as my understanding is very limited!

I am currently getting an "Internal Server Error" from uWSGI when I visit the reverse proxy url. In the uWSGI error log, I get the error:

--- no python application found, check your startup logs for errors ---

      

The app works fine when I only serve uWSGI starting with pserve. I can run it from my virtual envelope like this:

bin/pserve my-app/uwsgi.ini

      

But when I start nginx and visit the proxy address, I get an internal server error.

The settings I have in uwsgi.ini are as follows:

[app:main]
use = egg:myapp
pyramid.reload_templates = true
pyramid.debug_authorization = false
pyramid.debug_notfound = false
pyramid.debug_routematch = false
pyramid.default_locale_name = en
pyramid_debugtoolbar
[server:main]
use = egg:waitress#main
host = 0.0.0.0
port = 6543

[loggers]
keys = root, musiccircle

[handlers]
keys = console

[formatters]
keys = generic

[logger_root]
level = ERROR
handlers = console
[logger_musiccircle]
level = ERROR
handlers =
qualname = musiccircle

[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

[uwsgi]
socket = unix://home/usr/env/myapp/myapp.sock
master = true

processes = 48
cpu-affinity = 12

harakiri = 60
post-buffering = 8192
buffer-size = 65535

daemonize = ./uwsgi.log
pidfile = ./pid_5000.pid

listen = 32767

reload-on-as = 512
reload-on-rss = 192
limit-as = 1024
no-orphans = true
reload-mercy = 8
log-slow = true

virtualenv = /home/usr/env

      

And in the corresponding myapp.conf file in nginx, I have the following:

upstream myapp {
    server 127.0.0.1:6543;
}

server {
    listen          8080;
    server_name myapp.local www.myapp.local;
    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        root /home/usr/env/myapp;
    }
    access_log      /var/log/nginx/access.log;
    error_log       /var/log/nginx/error.log;

    charset         utf-8;
    location / {
        include         uwsgi_params;
        uwsgi_pass      unix://home/usr/env/myapp/myapp.sock;
    }
}

      

If you need to see anything else, please let me know. As you can see, Nginx is configured to serve on port 8080 (which it does), while the Pyramid application is served by uWSGI on port 6543 (which it does).

Thanks in advance.

+3


source to share


1 answer


It seems that Pyramid projects are meant to be installed ( setup.py

) and then run with a config file .ini

with pserve

. Pserve then passes this config file data as it is **settings

to your Pyramid application at runtime.

This differs from, for example, Flask, which is not installed and usually does not have a config file. Such a Flask application can be launched with uWSGI as needed, with all runtime configuration handled by uWSGI variables or the environment.



Since Pyramid usually needs a runtime config file and relies on pserve to provide them when using a config file (i.e. production.ini

), I think you will have to run uwsgi --ini-paste production.ini

(or if running Pypy, uwsgi --pypy-paste production.ini

) (thanks to @Sorrel)

+1


source







All Articles