【问题标题】:Rails Nginx config can not reach root urlRails Nginx 配置无法访问根 url
【发布时间】:2015-12-22 12:15:08
【问题描述】:

这是我的 nginx 配置

server {
listen 80;
server_name localhost;

root /home/user/app/public;

try_files $uri/index.html $uri @app;

location @app {
    proxy_pass http://app;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;
}

error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}

假设我的公共 ip:111.111.111.111

当我尝试输入站点 111.111.111.111/path 时,它工作正常,但是当我尝试仅输入根 url 111.111.111.111 时,它给了我“欢迎使用 nginx”消息。我查看了nginx日志,但是没有关于root url的内容。

我也在使用独角兽,但我认为这没有问题,我假设我已经在此处添加了必要的配置部分。

【问题讨论】:

  • “欢迎使用 nginx”应该是 nginx 安装的默认 index.html。您确实在try_files 中有$uri/index.html 作为第一个,这是您的意图吗?您可以删除/重命名 index.html 或在 try_files 中删除/重命名它 - 这会改变行为吗?
  • 我已将其删除,但没有任何变化。我不明白为什么 nginx 日志中也没有任何内容
  • @RamazanZor 试试location / { try_files $uri/index.html $uri @app; }
  • 它不起作用,有趣的是,即使我在根 url 中停止 nginx 服务,它仍然显示“欢迎使用 nginx”消息
  • 我找到了问题,只是浏览器缓存的问题,我删除了问题解决了

标签: ruby-on-rails ruby-on-rails-4 nginx web-deployment


【解决方案1】:

我认为它可能缺少独角兽 .sock 文件:在此处查看示例 nginx/unicorn/rails 配置:https://www.digitalocean.com/community/tutorials/how-to-deploy-a-rails-app-with-unicorn-and-nginx-on-ubuntu-14-04

您在 proxy_pass 行中引用了 upstream,但它没有定义。尝试将其添加到顶部:

upstream app {
  # Path to Unicorn SOCK file
  server unix:/path/to/your/app/shared/sockets/unicorn.sock fail_timeout=0;
} 

我刚刚看了一个不久前用 rails、unicorn 和 nginx 做的应用程序,我的条目是

server unix:/tmp/.sock fail_timeout=0;

这取决于你的独角兽是如何配置的,关于 sock 文件的位置,所以你需要调整它以指向正确的位置。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-10-30
    • 1970-01-01
    • 2021-10-21
    • 1970-01-01
    • 2015-03-12
    • 1970-01-01
    • 2019-04-07
    • 2017-05-29
    相关资源
    最近更新 更多