【问题标题】:nginx passenger standalone prevent proxy_pass on subdirectorynginx 乘客独立阻止子目录上的 proxy_pass
【发布时间】:2017-07-05 08:34:00
【问题描述】:

我正在运行 nginx 作为乘客独立 Rails 服务器的反向代理。 我需要在乘客独立端口 (5000) 上设置 root / 位置,但很少有其他子目录必须由“纯”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 错误。 有什么解决办法吗?

【问题讨论】:

    标签: ruby-on-rails nginx passenger proxypass


    【解决方案1】:

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

    【讨论】:

    • 嗨@aBadAssCowboy 谢谢你的回复。我已经尝试在位置 / 之前移动位置 /subdir 但不起作用。我认为 location /subdir 语句不正确。
    猜你喜欢
    • 2012-04-12
    • 1970-01-01
    • 2011-10-01
    • 1970-01-01
    • 2017-02-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-19
    相关资源
    最近更新 更多