nginx proxy_pass POST 404 errors

Posted by Scott on Server Fault See other posts from Server Fault or by Scott
Published on 2012-12-07T02:06:28Z Indexed on 2012/12/07 5:08 UTC
Read the original article Hit count: 480

Filed under:
|
|
|

I have nginx proxying to an app server, with the following configuration:

location /app/ {
        # send to app server without the /app qualifier
        rewrite /app/(.*)$ /$1 break;
        proxy_set_header Host $http_host;
        proxy_pass http://localhost:9001;
        proxy_redirect http://localhost:9001 http://localhost:9000;
    }

Any request for /app goes to :9001, whereas the default site is hosted on :9000.

GET requests work fine. But whenever I submit a POST request to /app/any/post/url it results in a 404 error. Hitting the url directly in the browser via GET /app/any/post/url hits the app server as expected.

I found online other people with similar problems and added

proxy_set_header Host $http_host;

but this hasn't resolved my issue.

Any insights are appreciated.

Thanks.

Full config below:

server {
    listen   9000; ## listen for ipv4; this line is default and implied
    #listen   [::]:80 default_server ipv6only=on; ## listen for ipv6

    root /home/scott/src/ph-dox/html;
    # root ../html; TODO: how to do relative paths?
    index index.html index.htm;

    # Make site accessible from http://localhost/
    server_name localhost;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ /index.html;
        # Uncomment to enable naxsi on this location
        # include /etc/nginx/naxsi.rules
    }

    location /app/ {
        # rewrite here sends to app server without the /app qualifier
        rewrite /app/(.*)$ /$1 break;
        proxy_set_header Host $http_host;
        proxy_pass http://localhost:9001;
        proxy_redirect http://localhost:9001 http://localhost:9000;
    }

    location /doc/ {
        alias /usr/share/doc/;
        autoindex on;
        allow 127.0.0.1;
        allow ::1;
        deny all;
    }

}

© Server Fault or respective owner

Related posts about nginx

Related posts about 404