2

尝试在 vps 上部署我的第一个 rails 应用程序。我已按照以下设置中的说明进行操作。

https://www.digitalocean.com/community/articles/how-to-1-click-install-ruby-on-rails-on-ubuntu-12-10-with-digitalocean

但是我的站点出现 504 网关超时。

在 nginx 日志中,我得到以下信息:

2013/10/16 03:10:45 [error] 19627#0: *82 connect() failed (111: Connection refused) while connecting to upstream, client: 121.218.167.90, server: _, request: "GET / HTTP/1.1", upstream: "http://162.243.39.196:8080/", host: "162.243.39.196"

当我尝试运行独角兽时,我得到以下信息

E, [2013-10-16T04:26:28.530019 #30087] ERROR -- : adding listener failed addr=0.0.0.0:8080 (in use)

我的 nginx 默认文件有以下内容

server {
        listen   80;
        root /home/rails/public;
        server_name _;
        index index.htm index.html;

        location / {
                try_files $uri/index.html $uri.html $uri @app;
        }

        location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|mp3|flv|mpeg|avi)$ {
                        try_files $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_server;
    }

}

我的 /home/unicorn/unicorn.conf 有

listen "127.0.0.1:8080"
worker_processes 2
user "rails"
working_directory "/home/rails"
pid "/home/unicorn/pids/unicorn.pid"
stderr_path "/home/unicorn/log/unicorn.log"
stdout_path "/home/unicorn/log/unicorn.log"

谢谢你的帮助。

4

1 回答 1

1

您缺少在 中引用的上游块proxy_pass http://app_server;。您可以像这样将它放在服务器块上方。

upstream app_server {
    server 127.0.0.1:8080 fail_timeout=0;
}

server {
    listen   80;
    root /home/rails/public;
    server_name _;
    index index.htm index.html;
    ...
于 2013-10-16T15:54:44.977 回答