Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Interesting question I have this python code:

import sys, bottle, gevent
from bottle import *
from gevent import *
from gevent.wsgi import WSGIServer

@route("/")
def index():
    yield "/"

application=bottle.default_app()
WSGIServer(('', port), application, spawn=None).serve_forever()

that runs standalone with nignx infront of it as a reverse proxy.
Now each of these pieces of code run separately but I run multiple of these per domain per project(directory) but the code thinks for some reason that it is top level and its not so when you go to mydomain.com/something it works but if you go to mydomain.com/something/ you will get an error. No I have tested and figured out that nginx is stripping the "something" from the request/query so that when you go to mydomain.com/something/ the code thinks you are going to mydomain.com// how do I get nginx to stop removing this information?

Nginx site code:

upstream mydomain {
        server 127.0.0.1:10100 max_fails=5 fail_timeout=10s;
}
upstream subdirectory {
        server 127.0.0.1:10199 max_fails=5 fail_timeout=10s;
}

server {
        listen 80;
        server_name mydomain.com;
        access_log /var/log/nginx/access.log;
        location /sub {
                proxy_pass http://subdirectory/;
                proxy_redirect off;
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_max_temp_file_size 0;
                client_max_body_size 10m;
                client_body_buffer_size 128k;

                proxy_connect_timeout 90;
                proxy_send_timeout 90;
                proxy_read_timeout 90;

                proxy_buffer_size 4k;
                proxy_buffers 4 32k;
                proxy_busy_buffers_size 64k;
                proxy_temp_file_write_size 64k;
        }
        location /subdir {
                proxy_pass http://subdirectory/;
                proxy_redirect off;
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_max_temp_file_size 0;
                client_max_body_size 10m;
                client_body_buffer_size 128k;

                proxy_connect_timeout 90;
                proxy_send_timeout 90;
                proxy_read_timeout 90;

                proxy_buffer_size 4k;
                proxy_buffers 4 32k;
                proxy_busy_buffers_size 64k;
                proxy_temp_file_write_size 64k;
        }
}
share|improve this question
add comment

1 Answer 1

I figured it out :]

apparently in the proxy_pass you need to tell it the subdirectory just like the request will be:

location /sub {
            proxy_pass http://subdirectory/sub; // here the location ie: /sub needs to be passed to the underlieing 
            proxy_redirect off;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_max_temp_file_size 0;
            client_max_body_size 10m;
            client_body_buffer_size 128k;

            proxy_connect_timeout 90;
            proxy_send_timeout 90;
            proxy_read_timeout 90;

            proxy_buffer_size 4k;
            proxy_buffers 4 32k;
            proxy_busy_buffers_size 64k;
            proxy_temp_file_write_size 64k;
}
share|improve this answer
    
As a note I actually figured it out after reading for about an hour of the documentation on nginx yet serverfault would not let me upload my own answer for another 6 hours –  gabe Jun 24 '12 at 17:45
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.