Nginx + Unicorn 子域名虚拟主机失败(超时)

Nginx + Unicorn 子域名虚拟主机失败(超时)

我在 VPS 上设置了一台服务器,通过 Nginx + Unicorn 提供生产 Rails 应用程序。目前,使用以下配置文件可以正常工作:

然而,添加的子域staging.appname.tld最终导致以下错误/var/log/nginx/error.log

2012/08/20 16:57:39 [error] 24673#0: *174 upstream timed out (110: Connection timed out) while reading response header from upstream, client: xxx.xxx.xxx.xxx, server: staging.appname.com, request: "GET / HTTP/1.1", upstream: "http://unix:/tmp/unicorn.appname_staging.sock:/", host: "staging.appname.com"
2012/08/20 16:58:17 [error] 24673#0: *178 upstream timed out (110: Connection timed out) while reading response header from upstream, client: xxx.xxx.xxx.xxx, server: staging.appname.com, request: "GET / HTTP/1.1", upstream: "http://unix:/tmp/unicorn.appname_staging.sock:/", host: "staging.appname.com"
2012/08/20 16:59:29 [error] 24673#0: *182 upstream timed out (110: Connection timed out) while reading response header from upstream, client: xxx.xxx.xxx.xxx, server: staging.appname.com, request: "GET / HTTP/1.1", upstream: "http://unix:/tmp/unicorn.appname_staging.sock:/", host: "staging.appname.com"

出现此错误的配置是:

此外,袜子确实存在!如果我们查看 /tmp/,我们会看到unicorn.appname.sockunicorn.appname_staging.sock

这里nginx -V输出。

看起来好像配置中有些不对劲,但我就是没看到。有人能告诉我这个错误是从哪里来的吗,以及如何在此上下文中正确设置子域(例如暂存环境)?

答案1

我没有发现您的配置有什么问题,虽然有些小问题需要改进,但不会破坏它。您能否激活调试日志并在此处发布日志。

请查看以下修改后的配置(已激活调试日志)。

upstream unicorn_appname_staging {
  server unix:/tmp/unicron.appname_staging.sock max_fails=0;
}

server {
  listen 80;
  index index.html;
  root /home/deployer/apps/appname/staging/current/public;
  server_name staging.appname.com;

  client_max_body_size 4G;
  keepalive_timeout 10;

  access_log /var/log/nginx/staging.appname.com.access.log;
  error_log /var/log/nginx/staging.appname.com.error.log debug;
  error_page 500 502 503 504 /500.html;

  location / {
    location ^~ /assets/ {
      gzip_static on;
      expires max;
      add_header Cache-Control public;
    }

    try_files $uri @unicorn_appname_staging;
  }

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

相关内容