Pylons / pyramid_blogr

Pyramid_blogr is an example implementation of Flaskr app with Pyramid Web Framework
73 stars 39 forks source link

unable to host in production with Nginx #64

Closed AlexanderMcNulty closed 7 years ago

AlexanderMcNulty commented 7 years ago

In a shell:

$ git clone https://github.com/Pylons/pyramid_blogr.git
$ cd pyramid_blogr
$ python3.6 -m venv env
$ ./env/bin/pip3 install pyramid==1.7
$ ./env/bin/pip3 install -e .
$ initialize_pyramid_blogr_db development.ini
$ pserve development.ini

In another shell:

$ cat > nginx.conf <<EOF
events {
    worker_connections  1024;
}

http {
        server {
                listen 3456;
                location / {
                        proxy_pass http://127.0.0.1:6543;
                }
        }
}

daemon off;
EOF
$ nginx -c nginx.conf

Visit localhost:3456 in your web browser.

Notice the form on the page posts to 127.0.0.1:6543, a different host.

Expected the form to post to 127.0.0.1:3456.

digitalresistor commented 7 years ago

You should be setting up the appropriate HTTP headers so that Waitress or whatever Python web-server you are using can set up the WSGI environment properly:

        proxy_set_header    Host $host;
        proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_http_version  1.1;
        proxy_set_header    X-Forwarded-Proto $scheme;

For example will do the right thing. This is an NGINX configuration issue, not an issue with pyramid_blogr or with waitress, Caddy apparently forwards these headers already.