【问题标题】:PHP and Rails for NginX configuration用于 NginX 配置的 PHP 和 Rails
【发布时间】:2012-10-11 21:56:44
【问题描述】:

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

location / {
    index index.php; 
}

如果 URL 像 /foo/bar /foo/bar/index.php 被提供。

但现在我也有 Rails(乘客),根据这条规则,我不能撞到铁轨。 如何检查之前是否存在 index.php 并仅在不存在时才点击 rails。

谢谢。

【问题讨论】:

    标签: php ruby-on-rails nginx rewrite passenger


    【解决方案1】:

    如果我理解您的问题,您将需要定义另一个位置块,“命中”轨道并在当前位置使用 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;
    }
    

    这些将是此类配置的必要部分,当然它缺少代理配置。 a more detailed example for similar application

    【讨论】:

    • 什么是 unix:/tmp/thin.0.socket;?它应该是乘客的插座吗?
    • 它应该是为您的 rails 服务的任何应用程序的套接字。 Thin 就是这样一个例子。
    【解决方案2】:

    应该try_files

    server {
            try_files $uri $uri/ $uri/index.php @passenger;
    
            location @passenger {
                    passenger_enabled on;
                    rails_env development;
            }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-09-17
      • 1970-01-01
      • 2017-10-31
      • 2021-08-14
      • 2014-11-10
      • 1970-01-01
      • 2015-03-13
      • 1970-01-01
      相关资源
      最近更新 更多