【问题标题】:Nginx not detecting the root location from config for Rails 3.2 appNginx 未从 Rails 3.2 应用程序的配置中检测到根位置
【发布时间】:2014-07-07 20:00:43
【问题描述】:

这是在 ubuntu 12.04 上运行的 nginx 服务器的 error.log。

2014/03/17 12:47:17 [error] 7939#0: *1 open() "/opt/nginx/html/mkl/authentify/signin" failed (2: No such file or directory), client: xxx.xxx.228.66, server: xxx.xxx.109.181, request: "GET /mkl/authentify/signin HTTP/1.1", host: "xxx.xxx.109.181"

在/opt/nginx/conf/nginx.conf中,配置如下(conf中唯一的server块):

  server {
    listen 80;
    server_name xxx.xxx.109.181;
    root /ebs/www/;
    passenger_enabled on;
    rails_env production;
    passenger_base_uri /mkl;
    .....
  }

nginx服务器的根目录指向/ebs/www/。但是 nginx 正在访问 /opt/nginx 并且没有抛出这样的文件错误。是什么导致了问题?谢谢。

在安装 gem passenger 之后,nginxpassenger-install-nginx-module 一起安装。

【问题讨论】:

  • 检查您的配置文件是否从正确的位置读取。尝试运行nginx -t
  • 刚出差回来,抱歉回复慢。 nginx -t 返回:程序 'nginx' 可以在以下包中找到: * nginx-extras * nginx-full * nginx-light * nginx-naxsi

标签: ruby-on-rails ruby-on-rails-3 nginx passenger


【解决方案1】:

正确地说,root 是您应用程序中的公共命令:

server {
  listen 80;
  server_name xxx.xxx.109.181;
  root /ebs/www/YOUR_APPLICATION/current/public;
  # e.g. root /var/www/vhosts/example.com/httpdocs/example/current/public;
  passenger_enabled on;
  rails_env production;
  passenger_base_uri /mkl;
  .....
}

【讨论】:

    【解决方案2】:

    在 nginx.conf 中的第一个(唯一)服务器块之后再添加一个 server {} 块后,该问题已得到解决。在以前的版本(可能是 1.4.x)中,nginx.conf 中有 2 个服务器块。在当前版本中,只有一个 server {} 块。

    有关该解决方案的更多信息,请访问Why is nginx responding to any domain name?https://serverfault.com/questions/416064/rails-application-only-showing-nginx-default-page

    【讨论】:

    • 添加另一个服务器{} 块应该没关系。如果在唯一服务器块中配置了根,则应将其用于所有请求。我怀疑你观察到的是乘客问题。如果您使用来自 nginx.org 的 vanilla nginx 检查相同的配置(减去与乘客相关的指令)以确保它确实是乘客问题(而不是 nginx 中的一些晦涩的错误),那将是很酷的。
    猜你喜欢
    • 1970-01-01
    • 2013-02-18
    • 1970-01-01
    • 2012-08-04
    • 2015-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多