简体   繁体   English

nginx乘客独立版本防止在子目录上使用proxy_pass

[英]nginx passenger standalone prevent proxy_pass on subdirectory

i'm running nginx as reverse proxy for passenger standalone rails server. 我正在将nginx作为乘客独立Rails服务器的反向代理运行。 I need to set up root / location on passenger standalone port (5000) but few other subdirectories must be served by "pure" nginx. 我需要在乘客独立端口(5000)上设置根目录/位置,但是“纯” 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. https://example.com/subdir/始终返回404错误。 Any tips to fix it? 有解决问题的技巧吗?

Move the location directive for /subdir above the root location's direction. /subdir的location指令/subdir根位置的方向上方。 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;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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