【问题标题】:Unable to access Rails app on NGinx and Thin without port in URL无法在 URL 中没有端口的情况下访问 NGinx 和 Thin 上的 Rails 应用程序
【发布时间】:2014-06-26 10:53:18
【问题描述】:

所以我使用非常标准的 NGinx 和 Thin 配置部署了我的 Rail 3 应用程序。但我遇到了三个问题 -

  • 我只能通过将端口附加到 URL (domain.com:port) 来访问应用程序
  • www.domain.com 仍然显示 NGinx 欢迎屏幕和
  • 理想情况下,使用 URL 中的端口访问应用程序应该不起作用

我的 NGinx 配置:

upstream thin_cluster {
    <ip_address>:3000;
    <ip_address>:3001;
    <ip_address>:3002;
}

server {
        listen       80;
        server_name  domain.com www.domain.com;

        root /home/deployer/apps/appname/current/public;

        location ^~ /assets/ {
        gzip_static on;
        gzip_disable "msie6";
        expires max;
        add_header Cache-Control public;
        }

        location / {
                try_files $uri @thin;
        }   

        location @thin {
        proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_pass http://thin_cluster;
        }

        error_page   500 502 503 504 /500.html;

        client_max_body_size 50M;
        keepalive_timeout 10;
}

我的瘦身:

---
chdir: /home/deployer/apps/appname/current
environment: production
address: 0.0.0.0
port: 3000
timeout: 30
log: log/thin.log
pid: tmp/pids/thin.pid
max_conns: 1024
max_persistent_conns: 100
require: []
wait: 30
servers: 3
daemonize: true
onebyone: true

【问题讨论】:

    标签: ruby-on-rails nginx thin


    【解决方案1】:

    好的,已经无数次回答我的问题了。这是一个非常愚蠢的错误,可能是因为睡眠不足。

    问题就在这里

    upstream thin_cluster { <ip_address>:3000; <ip_address>:3001; <ip_address>:3002; }

    它应该包含运行 Thin 的本地主机地址。所以这将是:

    upstream thin_cluster { 127.0.0.1:3000; 127.0.0.1:3001; 127.0.0.1:3002; }

    但是,我仍然可以通过将端口号附加到应用程序来访问它。理想情况下,这应该重定向到正确的 URL。或许proxy_redirect 可以帮忙?

    【讨论】:

    • 您需要为本地端口设置防火墙或使用套接字连接方案。
    猜你喜欢
    • 1970-01-01
    • 2011-09-18
    • 2017-05-08
    • 1970-01-01
    • 2021-05-16
    • 2016-04-03
    • 2013-05-15
    • 1970-01-01
    • 2012-08-04
    相关资源
    最近更新 更多