【发布时间】:2015-07-07 19:29:36
【问题描述】:
我的 rails nginx/unicorn 服务器出现上游超时错误。我已尝试解决此问题,但没有找到任何适合我的解决方案。
我正在粘贴我在 nginx error.log 文件中遇到的确切错误:
upstream timed out (110: Connection timed out) while reading response header from upstream, client: xxx.xxx.xxx.xxx, server: default_server, request: "GET / HTTP/1.1", upstream: "http://unix:/tmp/unicorn.todo.socket/", host: "xxx.xxx.xxx.xxx"
我正在关注以下 2 篇关于在我的 ubuntu EC2 机器中使用 Ruby on Rails 应用程序设置 nginx 和 unicorn 的博客:
- https://gist.github.com/billie66/3696537
- https://www.digitalocean.com/community/tutorials/how-to-deploy-a-rails-app-with-unicorn-and-nginx-on-ubuntu-14-04
我可以在生产环境中在端口 3000 上运行服务器,但现在,我需要在端口 80 上运行服务器,以便我可以将 DNS 指向我的服务器 IP。我使用了以下方法来运行它:
unicorn.todo.socket 是在使用此命令在 unicorn 上运行应用程序后创建的 -
unicorn -c config/unicorn.rb -E production在sites-available/default中,所有配置都正确,包括上游。
在启用站点/默认设置中,配置与站点可用/默认设置相同,因为它们都是链接的。该文件包含在 /etc/nginx/ 目录下的 nginx.conf 文件中。
在日志中,我收到上游超时错误。这也表明 nginx 需要时间连接到 unicorn.todo.socket 但无法调试这部分,因为所有配置都正确并且在其他服务器上正确运行相同的东西。
我已经使用 'sudo nginx -t' 命令检查了 nginx 配置,这也显示一切正常。
超时后,公用文件夹出现ruby 500页面错误,说明路径等配置也正确。
我已经完全删除了 nginx 和相关组件并重新安装到服务器,但再次没有成功。
当我运行
sudo service nginx restart时,它会重新启动 nginx,我可以看到 nginx 服务器以某个 pid 运行。我已经更改了 unicorn.rb 监听路径的路径,这也不起作用。
我用于此服务器的独角兽版本正在另一台服务器上运行,因此我没有更改此设置。
添加了
proxy_read_timeout 150,但这也不起作用。
请检查我已经尝试过的所有上述内容,如果我缺少任何使用 nginx/unicorn 在端口 80 上运行服务器的内容,请告诉我。
/etc/nginx/sites-enabled/默认
upstream app {
server unix:/tmp/unicorn.todo.socket fail_timeout=0;
}
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name default_server;
root /home/ubuntu/<project_folder>/public;
try_files $uri/index.html $uri @app;
location @app {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app;
proxy_read_timeout 150;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}
【问题讨论】:
-
你见过this吗?您可以在帖子中包含完整的 NGINX 配置文件吗?
-
是的,我已经看到了这个并根据这个改变了我的配置,但没有工作。在此之后我再次恢复了我的代码。请检查 Nginx 配置文件。默认的 nginx.conf 文件和默认生成的一样。
-
可能不相关,但是为了服务器域名(不是IP地址),您需要正确设置
server_name(例如server_name example.com)。 -
我还通过注释掉服务器名称进行了检查,因为我现在正在检查 IP。我还没有指向 DNS。
-
我要检查的唯一另一件事是您的应用程序对您的套接字文件具有写入权限,并且您的 Unicorn 启动文件引用了您的套接字路径/文件。
标签: ruby-on-rails http nginx amazon-ec2 unicorn