ruby-on-rails - Passenger + Rails 应用仅适用于端口 3000

标签 ruby-on-rails ruby ruby-on-rails-4 passenger ports

Passenger 将在端口 80 上启动,但只会显示主页(100% HTML)。没有其他页面将解析。更奇怪的是,所有无法解析的流量都被转发到 HTTPS(当然,它也无法解析)。

这个有效:

rvmsudo passenger start --daemonize

这不起作用:

rvmsudo passenger start --daemonize --port 80

我的 config.ru 也很标准:

require ::File.expand_path('../config/environment',  __FILE__)
run Rails.application

我在 Passenger 5.0.7 中使用 Rails 4.2.0 和 Ruby 2.2.2

有人有什么想法吗?

nginx 配置文件:

user www-data;
worker_processes 4;
pid /run/nginx.pid;

events {
    worker_connections 768;
    # multi_accept on;
}

http {
    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;
    gzip_disable "msie6";

    ##
    # nginx-naxsi config
    ##
    # Uncomment it if you installed nginx-naxsi
    ##

    #include /etc/nginx/naxsi_core.rules;

    ##
    # nginx-passenger config
    ##
    # Uncomment it if you installed nginx-passenger
    ##

    passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini
    #passenger_ruby /home/ubuntu/.rvm/gems/ruby-2.2.2

应用特定配置:

map $http_upgrade $connection_upgrade {
    default upgrade;
    ''      close;
}

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

    # Tells Nginx to serve static assets from this directory.
    root /var/www/mydomain/public;

    location / {
        # Tells Nginx to forward all requests for www.foo.com
        # to the Passenger Standalone instance listening on port 4000.
        proxy_pass http://127.0.0.1:4000;

        # These are "magic" Nginx configuration options that
        # should be present in order to make the reverse proxying
        # work properly. Also contains some options that make WebSockets
        # work properly with Passenger Standalone. Please learn more at
        # http://nginx.org/en/docs/http/ngx_http_proxy_module.html
        proxy_http_version 1.1;
        proxy_set_header Host $http_host;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
        proxy_buffering off;
    }
}

最佳答案

如果你想在 nginx 后面运行乘客,我认为你需要一个不同的“设置”/配置。

Nginx 应该监听端口 80(它在您的 nginx.conf 的服务器部分中指定),并将流量转发到您在乘客引擎盖下运行的应用程序(在 nginx.conf 中指定在端口 4000 上,但手动启动在 80 端口),如果我没有看错的话。

我相信 nginx 可能会在其日志文件/var/log/nginx.log 中告诉您它不满意。您可以通过执行 netstat -tlpn 来确认端口 80 上有什么。

关于ruby-on-rails - Passenger + Rails 应用仅适用于端口 3000,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30106200/

相关文章:

ruby-on-rails - 具有不同数据库表的 ActiveRecord 继承

ruby-on-rails - Ruby on Rails 中 options.dup 的用途是什么?

ruby - Ruby 中的普通旧对象?

ruby - 为什么 ruby​​ 的 JSON 解析器会吃掉我的反斜杠?

ruby-on-rails-4 - 获取 Rails 中第一条记录的 "id"的最有效方法

multithreading - 当 allow_concurrency = true 时 Rails 停止记录

ruby-on-rails - Rails 4中的参数化连接

ruby-on-rails - Devise - 确认后重定向到重发确认指令页面

ruby-on-rails - Cucumber 和 webrat - 如何处理 paths.rb 中的动态 URL?

javascript - 如何将表单操作设置为 javascript :; on ruby on rails