我在同一台服务器上同时运行PHP和Rails。我曾经在nginx.conf上有一个重写规则
location / {
index index.php;
}
如果提供了像/foo/bar
/foo/bar/index.php
这样的URL。
但现在我也有轨道(乘客(,有了这个规则,我不能撞到轨道。如何检查是否存在索引.php之前,只有在不存在时才命中轨道。
谢谢。
如果我理解了您的问题,您将需要定义另一个位置块,该块"命中"轨道并在当前位置中使用try_files。像这样的东西。
index index.html index.php # better place this outside location block
upstream thin {
unix:/tmp/thin.0.socket; # this could be any other rails server socket
unix:/tmp/thin.1.socket;
}
location / {
try_files $uri @rails;
}
location @rails {
proxy_pass http://thin;
}
这些将是此类配置的重要组成部分,当然它缺少代理配置。类似应用的更详细示例
应该try_files
server {
try_files $uri $uri/ $uri/index.php @passenger;
location @passenger {
passenger_enabled on;
rails_env development;
}
}