简体   繁体   中英

nginx passenger standalone prevent proxy_pass on subdirectory

i'm running nginx as reverse proxy for passenger standalone rails server. I need to set up root / location on passenger standalone port (5000) but few other subdirectories must be served by "pure" nginx. I'm trying configurations like

server {
    listen 443;

    root /path/to/rails/public;

    server_name example.com;

    ssl on;
    # ... some ssl config

    # this is used for passenger standalone on port 5000
    location / {
            proxy_pass https://127.0.0.1:5000;
            proxy_http_version 1.1;
            proxy_set_header Host $http_host;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection $connection_upgrade;
            proxy_buffering off;
    }

    # this is not passenger standalone! 
    location /subdir {
            proxy_pass https://127.0.0.1;
            auth_basic "Restricted access area authorization needed.";
            auth_basic_user_file /path/to/.htpasswd;
    }

}

but https://example.com/subdir/ return always 404 error. Any tips to fix it?

Move the location directive for /subdir above the root location's direction. The request paths are matched in the order defined in the configuration.

server {
    listen 443;

    root /path/to/rails/public;

    server_name example.com;

    ssl on;
    # ... some ssl config

    # this is not passenger standalone! 
    location /subdir {
            proxy_pass https://127.0.0.1;
            auth_basic "Restricted access area authorization needed.";
            auth_basic_user_file /path/to/.htpasswd;
    }
    # this is used for passenger standalone on port 5000
    location / {
            proxy_pass https://127.0.0.1:5000;
            proxy_http_version 1.1;
            proxy_set_header Host $http_host;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection $connection_upgrade;
            proxy_buffering off;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM