nginx乘客独立防止子目录上的proxy_pass

时间:2017-07-05 08:34:00

标签: ruby-on-rails nginx passenger proxypass

我正在运行nginx作为乘客独立rails服务器的反向代理。 我需要在乘客独立端口(5000)上设置根/位置,但很少有其他子目录必须由“纯”nginx提供服务。 我正在尝试像

这样的配置
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;
    }

}

https://example.com/subdir/始终返回404错误。 有任何解决方法吗?

1 个答案:

答案 0 :(得分:0)

/subdir的位置指令移到根位置的方向上方。 请求路径按配置中定义的顺序进行匹配。

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;
    }
}