【问题标题】:Nginx not serving my test Rails appNginx 没有为我的测试 Rails 应用程序提供服务
【发布时间】:2015-08-28 02:08:25
【问题描述】:

我的 Ubuntu 14.04 VPS 上的 nginx 服务器有问题。我成功安装了Passenger(最新)和Nginx。现在我创建了测试 Rails 应用程序(rails 4.2.3)。我的应用路径是/home/testapp/public;

在 /opt/nginx/conf/nginx.conf 我有这个设置:

user  root;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    passenger_root /usr/local/rvm/gems/ruby-2.2.1/gems/passenger-5.0.15;
    passenger_ruby /usr/local/rvm/gems/ruby-2.2.1/wrappers/ruby;

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


    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

 #gzip  on;

    server {
        listen       80;
        server_name  localhost;
        root /home/testapp/public;
        passenger_enabled on;
        rails_env production;
        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }

    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    server {
        listen       8001;

        server_name  testapp.com;
        passenger_enabled on;
        root /home/testapp/public;


        location / {
            root   html;
            index  index.html index.htm;
        }
    }



    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

如您所见,端口 80 和 8001 上有两个服务器配置。转到这两个端口我有结果默认 nginx 页面。

Passenger、Nginx、Rails 都没有收到任何错误,一切正常。

注意:在安装 Passenger 和 nginx 模块时,我没有获得可用站点和已启用站点的文件夹,因此我在 /opt/nginx/ 路径中创建了这两个文件夹。

我需要做什么来显示我的 rails testapp 而不是 nginx 默认页面?

【问题讨论】:

  • 在 Ubuntu 14.04 中,支持 Nginx 站点的文件夹安装在这里:/etc/nginx/sites-enabled,配置文件是/etc/nginx/nginx.conf。

标签: ruby-on-rails ruby ubuntu nginx passenger


【解决方案1】:

在您的端口 80、8001 配置中删除

location / {
        root   html;
        index  index.html index.htm;
    }

因为这部分覆盖了root /home/testapp/public; 指令

【讨论】:

    【解决方案2】:

    这就是我在服务器标签中所需要的:

    server {
        listen       80;
        server_name  localhost;
        passenger_enabled on;
        root /home/testapp/public;
        rails_env production;
    }
    

    也被删除了:

    location / {
            root   html;
            index  index.html index.htm;
        }
    

    【讨论】:

      猜你喜欢
      • 2012-02-01
      • 2015-08-15
      • 1970-01-01
      • 1970-01-01
      • 2020-09-27
      • 2017-08-14
      • 2014-11-06
      • 2023-03-15
      相关资源
      最近更新 更多