Ruby 2.5.1,Rails 5.2.2.1
我正在尝试使nginx通过puma套接字进入上游。
当我运行rails s -e production
时一切都很好。
当我运行rails s -e production -d
时,Nginx返回502 Bad Gateway
config / puma.rb
...
app_dir = "/home/user/myapp"
tmp_dir = "#{app_dir}/tmp"
# Set up socket location
bind "unix://#{tmp_dir}/sockets/puma.sock"
# Logging
stdout_redirect "#{app_dir}/log/puma.stdout.log", "#{app_dir}/log/puma.stderr.log", true
...
etc / nginx / sites-enabled / mydomain.com
upstream app {
# Path to Puma SOCK file, as defined previously
server unix:/home/user/myapp/tmp/sockets/puma.sock fail_timeout=0;
}
server {
listen 80;
server_name mydomain.com;
root /home/user/myapp/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;
}
var / log / nginx / error.log
2019/07/07 13:45:09 [error] 21609#21609: *11391 connect() to
unix:/home/user/myapp/tmp/sockets/puma.sock failed (111: Connection
refused) while connecting to upstream, client: 172.68.11.91, server:
mydomain.com, request: "GET /pages/one HTTP/1.1", upstream:
"http://unix:/home/user/myapp/tmp/sockets/puma.sock:/pages/one", host: "mydomain.com"
(PS从原始域更改为mydomain.com) 有什么区别?如何解决?请解释和帮助
更新
似乎正在使用守护程序标志运行,它未在/ home / user / myapp / tmp / sockets中创建puma.sock
。为什么在哪里?
答案 0 :(得分:0)
解决方案
不知道为什么,但是如果运行puma(不是rails服务器),则可以正常工作
RAILS_ENV=production bundle exec puma -C config/puma.rb -d