ruby-on-rails - Nginx 到 Unicorn 的反向代理 - nginx 配置不正确?

标签 ruby-on-rails ubuntu nginx reverse-proxy unicorn

我关注了这个 tutorial配置我的 Rails 应用程序以运行 Unicorn,并由 Nginx 在我的 AWS ubuntu 实例上进行反向代理。

我可以访问 nginx,“欢迎使用 nginx!”默认页面,从外部在站点上运行(安全配置正确)。但它不服务于 rails 应用程序。

我的 unicorn 在 /home/ubuntu/appname/shared/sockets/unicorn.sock= 下运行

我跑了sudo service unicorn restart以防万一。
当我运行 sudo service --status-all它返回:[ ? ] unicorn_gpei-tk
正如我提到的 nginx 肯定正在运行,这里是位于 /etc/nginx/sites-available/default 中的配置:

upstream app {
    # Path to Unicorn SOCK file, as defined previously
    server unix:/home/ubuntu/appname/shared/sockets/unicorn.sock fail_timeout=0;
}

server {
    listen 80;
    server_name localhost;

    root /home/ubuntu/appname/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;
}
/etc/nginx/sites-enabled 中的符号链接(symbolic link)是 default -> /etc/nginx/sites-available/default -- 我想第二个问题是:启用站点是否必要?本教程没有提及/要求它,我在尝试破译这个问题的 1000 个其他资源之后遇到了这个问题。

其他信息:如果我以用户身份运行 Unicorn,我可以在端口 8080 上连接到它,所以 Unicorn 也可以自己运行并为网站提供服务。

而且我也重新启动了几次nginx服务,仍然没有更新配置,可能是因为我在某个地方出错了。

真的没有看到我错过了什么,有任何线索/想法吗?谢谢。

编辑:

我进入/var/log/nginx/error.log (有一个 error.log.1 但它似乎没有更新),这出现了:2016/07/28 16:21:19 [error] 11763#11763: *2 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: XX.XXX.XXX.XX, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "my_public_address.com", referrer: "http://my_public_address.com/"
和/var/log/nginx/access.log 是:XX.XXX.XXX.XX - - [28/Jul/2016:16:24:58 +0000] "GET /favicon.ico HTTP/1.1" 404 571 "http://my_public_address.com/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36" "-"

最佳答案

我发现了问题并修复了它。

您需要包含所需的配置。在/etc/nginx/nginx.conf 中注释掉默认配置,因为它指向 localhost。
在此处添加您想要的配置。在我的情况下是这样的:/etc/nginx/sites-available/*我那里只有一个配置文件,但感觉就像放 *.

重启nginx服务。
现在很多新手头痛的时间都过去了。

关于ruby-on-rails - Nginx 到 Unicorn 的反向代理 - nginx 配置不正确?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38641524/

相关文章:

ruby-on-rails - 自定义错误页面 - Ruby on Rails

ruby-on-rails - Heroku 上的 Redis::ConnectionError

ruby-on-rails - Rails 6 和 Google Maps for Rails

ruby-on-rails - 如何获取查询以返回我的模拟对象?

Ubuntu 上的 PHP 从命令行加载 MSSQL 扩展,但在通过 Apache 运行时不加载

ruby-on-rails - Rails 4 生产 Assets 在 AWS ELB 和 nginx 上返回 502

ruby-on-rails - 重新启动后,如何保持乘客独立运行?

angular - 启动 Angular + ASP.Net Core 应用程序导致 'The SPA default page middleware could not return the default page '/index.html''

c++ - OpenGL Ubuntu 13.10 QtCreator - 未定义对 `glutMainLoop` 的引用

nginx - Centos7 Nginx mod_security - 未知指令 "ModSecurityEnabled"