【发布时间】:2015-04-18 14:39:05
【问题描述】:
在 CentOS 7.x 中,我安装了一个可以通过 [ip]:8080 访问的 Rails 应用程序。它使用ip工作。 但是当我将域名设置为 server_name(而不是 localhost)时,mydomain.com 给了我一个 502 Bad Gateway 问题。 ip 仍然有效。
我已经重启了 nginx。该应用程序正在使用 unicorn_rails 运行。我的 Rails 日志什么也没显示。 PD:这个应用程序来自这个tutorial。
/etc/nginx/conf.d/default.conf
upstream app {
# Path to Unicorn SOCK file, as defined previously
server unix:/tmp/unicorn.myapp.sock fail_timeout=0;
}
server {
listen 80;
server_name mydomain.com www.mydomain.com;
# Application root, as defined previously
root /var/www/my_app/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;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}
/var/www/my_app/config/unicorn.rb
# Set the working application directory
# working_directory "/path/to/your/app"
working_directory "/var/www/my_app"
# Unicorn PID file location
# pid "/path/to/pids/unicorn.pid"
pid "/var/www/my_app/pids/unicorn.pid"
# Path to logs
# stderr_path "/path/to/log/unicorn.log"
# stdout_path "/path/to/log/unicorn.log"
stderr_path "/var/www/my_app/log/unicorn.log"
stdout_path "/var/www/my_app/log/unicorn.log"
# Unicorn socket
#listen "/tmp/unicorn.[app name].sock"
listen "/tmp/unicorn.myapp.sock"
# Number of processes
# worker_processes 4
worker_processes 2
# Time-out
timeout 30
这是我的 /var/log/nginx/error.log 显示的内容:
2015/02/17 14:06:34 [crit] 14512#0: *375 connect() to unix:/tmp/unicorn.myapp.sock failed (2: No such file or directory) while connecting to upstream, client: 123.45.678.91, server: mydomain.com, request: "GET / HTTP/1.1", upstream: "http://unix:/tmp/unicorn.myapp.sock:/", host: "mydomain.com"
2015/02/17 14:06:36 [crit] 14512#0: *375 connect() to unix:/tmp/unicorn.myapp.sock failed (2: No such file or directory) while connecting to upstream, client: 123.45.678.91, server: mydomain.com, request: "GET / HTTP/1.1", upstream: "http://unix:/tmp/unicorn.myapp.sock:/", host: "mydomain.com"
第二个问题,应用程序只有在我运行unicorn_rails时才会执行,我怎样才能让它永久运行?
【问题讨论】:
-
你怎么在端口和 sock 文件上都运行 unicorn,检查你的 unicorn 设置并确保它默认使用 sock 文件,否则将你的上游更改为传递到端口 8080
-
你在运行
sudo service nginx restart后看到了什么,可能有帮助。还要检查文件/tmp/unicorn.myapp.sock,它是否可读和可写。 -
现在我看到了,该文件不存在。 ls 仅显示那些文件夹:缓存 pids 会话套接字。任何提示为什么没有创建那只袜子?
-
不,域名我不包括端口。这只是 mydomain.com。
标签: ruby-on-rails nginx unicorn