UWSGI: How to mount an insert application (Pyramid)?

What I have:

I have a Pyramid application that is created from Paste ini, is served by uWSGI and the nginx proxy. It works great. Here is the nginx configuration:

server { listen 80; server_name localhost; access_log /var/log/myapp/nginx.access.log; error_log /var/log/myapp/nginx.error.log warn; location / { uwsgi_pass localhost:8080; include uwsgi_params; } } 

Here is the configuration of uWSGI ini:

 [uwsgi] socket = 127.0.0.1:8080 virtualenv = /srv/myapp/venv die-on-term = 1 master = 1 logto = /var/log/myapp/uwsgi.log 

This configuration is located inside Pyramid production.ini , so I serve the application with this command:

 uwsgi --ini-paste-logged production.ini 

All of this works great.

What I want to do:

One simple change. I want to use this application as a subfolder, and not as a root. Instead of serving it from http://localhost , I want to serve it from http://localhost/myapp .

And now everything is broken.

If I change the nginx location directive from / to /myapp or /myapp/ , I get 404s because the WSGI application gets uris, all of which are added using /myapp .

The uWSGI solution is similar to mounting the WSGI to be called in a subfolder and then passing the --manage-script-name parameter, after which uWSGI should magically separate the subfix prefix from uri and fix the problem.

However, the documentation and any other resource I found only gave examples of the form:

 mount = /myapp=myapp.py 

I do not have myapp.py which contains WSGI because my called object is created by PasteDeploy.

So, is it possible to mount the WSGI called inside Paste ini? Or will I have to break up the uwsgi configuration from Paste ini, and also define a separate wsgi.py with a call to paste.deploy.loadapp to generate a wsgi callable that I can install?

Or is there another way to serve this application as a subfolder from nginx without messing up the backlink?

+5
source share
2 answers

Yes, it is definitely possible to mount your pyramid as a subdirectory with Nginx. What you need to use is the Modifier1 parameter from uWSGI, for example:

 location /myapp { include uwsgi_params; uwsgi_param SCRIPT_NAME /myapp; uwsgi_modifier1 30; uwsgi_pass localhost:8080; } 

The magic value of 30 tells uWSGI to remove the SCRIPT_NAME parameter from the beginning of PATH_INFO in the request. The pyramid receives the request and processes it correctly.

As long as you use the standard Pyramid technique to create URLs or paths in your application, SCRIPT_NAME automatically turned SCRIPT_NAME , which means that all URLs are for links / resources, etc. are correct.

The documentation is not very clear, but there are additional modifiers available at: https://uwsgi-docs.readthedocs.org/en/latest/Protocol.html

0
source

I wanted to do what you offer, but this is the closest solution I could find: if you want to change your PasteDeploy configuration, you can follow these steps: http://docs.pylonsproject.org/docs/pyramid/en /1.0-branch/narr/vhosting.html

Rename [app: main] to [app: mypyramidapp] and add a section:

 [composite:main] use = egg:Paste#urlmap /myapp = mypyramidapp 

I also had to add this to my nginx configuration:

 uwsgi_param SCRIPT_NAME ''; 

and install the paste module

 sudo pip3 install paste 

I wonder if there is a way to “install” PasteDeploy on the first question asked ...

0
source

All Articles