502 Bad Gateway, failed (13: Permission denied) - 使用 Nginx 和 Unicorn

502 Bad Gateway, failed (13: Permission denied) - with Nginx and Unicorn

我正在尝试使用 Nginx 和 Unicorn 将 rails 应用程序部署到 Azure。我一直在关注这个 tutorial 当我完成教程并启动网站时,我收到了 502 错误的网关错误。在我的 nginx error.log 中,我为每个页面加载得到这两行:

2015/05/10 19:04:37 [crit] 2784#0: *7 stat() "/var/www/offWhite/public/500.html" failed (13: Permission denied), client: 174.60.87.237, server: localhost, request: "GET / HTTP/1.1", upstream: "http://unix:/tmp/unicorn.offWhite.sock:/", host: "offfwhite.cloudapp.net"
2015/05/10 19:04:37 [crit] 2784#0: *7 connect() to unix:/tmp/unicorn.offWhite.sock failed (13: Permission denied) while connecting to upstream, client: 174.60.87.237, server: localhost, request: "GET / HTTP/1.1", upstream: "http://unix:/tmp/unicorn.offWhite.sock:/", host: "offfwhite.cloudapp.net"

我的 config/unicorn.rb 看起来和教程中的一样:

# Set the working application directory
# working_directory "/path/to/your/app"
working_directory "/var/www/offWhite"

# Unicorn PID file location
# pid "/path/to/pids/unicorn.pid"
pid "/var/www/offWhite/pids/unicorn.pid"

# Path to logs
# stderr_path "/path/to/log/unicorn.log"
# stdout_path "/path/to/log/unicorn.log"
stderr_path "/var/www/offWhite/log/unicorn.log"
stdout_path "/var/www/offWhite/log/unicorn.log"

# Unicorn socket
listen "/tmp/unicorn.offWhite.sock"

# Number of processes
# worker_processes 4
worker_processes 2

# Time-out
timeout 30

我的nginx也是default.conf:

upstream app {
    # Path to Unicorn SOCK file, as defined previously
    server unix:/tmp/unicorn.offWhite.sock fail_timeout=0;

}

server {


    listen 80;
    server_name localhost;

    # Application root, as defined previously
    root /var/www/offWhite/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;
}

根据我在网上发现的情况,经常会出现权限问题。如果还有其他选择,我还不想让 chmod 开心。

非常感谢

亚历克斯

我不确定这是否应该是服务器故障造成的。如果它应该让我知道,我会把它记下来。

编辑:

这是我每次启动服务器时在 unicorn.log 中得到的内容:

I, [2015-05-10T18:31:55.017694 #47698]  INFO -- : reaped #<Process::Status: pid 47701 exit 0> worker=0
I, [2015-05-10T18:31:55.017868 #47698]  INFO -- : reaped #<Process::Status: pid 47703 exit 0> worker=1
I, [2015-05-10T18:31:55.018017 #47698]  INFO -- : master complete
I, [2015-05-10T18:32:25.839675 #2048]  INFO -- : unlinking existing socket=/tmp/unicorn.offWhite.sock
I, [2015-05-10T18:32:25.840092 #2048]  INFO -- : listening on addr=/tmp/unicorn.offWhite.sock fd=10
I, [2015-05-10T18:32:25.840290 #2048]  INFO -- : worker=0 spawning...
I, [2015-05-10T18:32:25.841098 #2048]  INFO -- : worker=1 spawning...
I, [2015-05-10T18:32:25.841860 #2048]  INFO -- : master process ready
I, [2015-05-10T18:32:25.845775 #2053]  INFO -- : worker=1 spawned pid=2053
I, [2015-05-10T18:32:25.846049 #2053]  INFO -- : Refreshing Gem list
I, [2015-05-10T18:32:25.853470 #2051]  INFO -- : worker=0 spawned pid=2051
I, [2015-05-10T18:32:25.853751 #2051]  INFO -- : Refreshing Gem list
I, [2015-05-10T18:32:28.002957 #2051]  INFO -- : worker=0 ready
I, [2015-05-10T18:32:28.020675 #2053]  INFO -- : worker=1 ready

我在解决问题后的几个月里回答了我自己的问题,所以我没有我在推理中使用的确切日志。

基本上,unicorn 的日志中有一个错误,因为我从未将生产数据库声明为机密。