我正在运行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错误。 有任何解决方法吗?
答案 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;
}
}