dsaf32131
2012-08-22 08:36
浏览 72
已采纳

用于NginX配置的PHP和Rails

I have both PHP and Rails running on the same server. I used to have a rewrite rule at nginx.conf

location / {
    index index.php; 
}

and in case of URL like /foo/bar /foo/bar/index.php was served.

But now I have also Rails (Passenger) and with this rule I can't hit rails. How do I check if there exist index.php before and hit rails only if it does not.

Thanks.

图片转代码服务由CSDN问答提供 功能建议

我在同一台服务器上运行PHP和Rails。 我曾经在nginx.conf上有重写规则

  location / {
 index index.php;  
} 
   
 
 

如果是 / foo / bar /foo/bar/index.php这样的网址已服务。

但现在我还有Rails(Passenger)并且使用此规则我无法点击rails。 如何检查是否存在index.php之前和命中 只有在没有的情况下才会使用。

谢谢。

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • doudang9147 2012-10-11 13:56
    已采纳

    Should try_files

    server {
            try_files $uri $uri/ $uri/index.php @passenger;
    
            location @passenger {
                    passenger_enabled on;
                    rails_env development;
            }
    }
    
    已采纳该答案
    打赏 评论
  • doulu1544 2012-08-22 09:34

    If I understood Your question, You will need to define another location block, that "hits" rails and use try_files in current one. Something like this.

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

    These would be essential parts for such configuration, of course it lacks proxy configuration. a more detailed example for similar application

    打赏 评论

相关推荐 更多相似问题