【问题标题】:How do I get my website to display Welcome to Rails instead of Index of / in Ruby on Rails 5.2?如何让我的网站显示 Welcome to Rails 而不是 Ruby on Rails 5.2 中的 / 索引?
【发布时间】:2018-12-22 08:50:05
【问题描述】:

duelingpetWS2 水滴 地址:http://68.183.163.139/

当前安装:

NodeJS
NPM
Rbenv
ruby 2.5.1p57
Rails 5.2.2
MySQL
Ubuntu 18.04
nginx

/var/www/duelingpets.net/html/index.html

<html>
    <head>
        <title>Welcome to Duelingpets.net!</title>
    </head>
    <body>
        <h1>Success!  The duelingpets.net server block is working!</h1>
    </body>
</html>

新版本 /etc/nginx/sites-available/duelingpets.net

upstream duelingpets {
  server unix:///path/to/web/tmp/puma.sock;
}

server {
        listen 80;
        listen [::]:80;

        root /var/www/duelingpets.net/html;
        #index index.html index.htm index.nginx-debian.html;
        server_name duelingpets.net www.duelingpets.net;
        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://duelingpets;
        }
}

旧版本 /etc/nginx/sites-available/duelingpets.net

server {
        listen 80;
        listen [::]:80;

        root /var/www/duelingpets.net/html;
        index index.html index.htm index.nginx-debian.html;

        server_name duelingpets.net www.duelingpets.net;

        location / {
                try_files $uri $uri/ =404;
        }
}

sudo ln -s /etc/nginx/sites-available/duelingpets.net /etc/nginx/sites-enabled/

sudo vim /etc/nginx/nginx.conf

http {

        ##
        # Basic Settings
        ##

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

        server_names_hash_bucket_size 64;
        # server_name_in_redirect off;

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

网站的当前行为。

Welcome to nginx!

If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.

Thank you for using nginx.

【问题讨论】:

  • 显示 Rails 应用程序的 apache 配置,它指向 /public 目录,而不是将请求转发到 rails appserver 进程
  • 好的,我刚刚编辑了我的原始帖子并添加了 apache2 站点可用的 conf 文件。好的,它应该指向哪个部分?在 Rails 3.2 中,您最初必须将其指向 /public 目录才能使其工作。 Rails 5.2 需要指向哪里?

标签: ruby-on-rails apache digital-ocean ruby-on-rails-5.2


【解决方案1】:

我猜你正在使用 Puma 作为 Rails 的应用服务器,请查看这张票:https://github.com/puma/puma/issues/125

它设置了这个配置

<VirtualHost *:80>
    NameVirtualHost 99.99.99.99
    ServerName yourapp.com
    ServerSignature Off
    ProxyRequests Off
    <Proxy *>
        Order Allow,Deny
        Allow from all
    </Proxy>
    ProxyPass / http://localhost:3000/
    ProxyPassReverse / http://localhost:3000/
    ProxyVia On
</VirtualHost>

注意 localhost:3000 的代理密码,这是重要的部分(您不需要文档根目录)。

并确保您使用 puma -b tcp://127.0.0.1:3000 启动 puma,以便它通过 tcp 而不是套接字工作。

无论如何,我更喜欢使用 nginx 而不是 apache,您可以将 nginx 设置为使用套接字,这是 puma 默认启动的方式,并且有更多关于 nginx+puma 的教程(该链接上也有 nginx 的配置)。

【讨论】:

  • 我刚刚对此进行了测试,但无法使用您提供的代码使其正常工作。是否可以使用文档根目录以其他方式执行此操作?我正在使用 puma rails,因为它是默认设置。我过去使用过 apache 和 nginx,但我只有一个核心。如果我不必启动 puma 服务并让它自动运行,我更喜欢它,因为这将是一个远程服务器。如果可能的话,我也希望最终将其投入生产模式。过去我使用文档根目录使事情正常工作。我附上了在我的现场网站上运行的旧 apache2 版本。
  • 我不知道有任何其他方法可以做到这一点,要么是 tcp 与 localhost 的 proxypass,要么是使用套接字。如果您希望 puma 进程自动运行,请检查 systemd 或在 /etc/init.d 上放置脚本以自动启动服务器。
  • 好的。那么如何让它通过套接字版本运行呢?我很好奇我是否遗漏了什么,因为那个更接近完成。我认为现在默认情况下我认为 puma 在应用于数字海洋服务器时正在运行。我猜是因为我的rails已经自动运行了。
  • 我猜如果没有你配置 rails 不会自动运行,你可以检查它启动 vps 并运行 ps ax | grep 'puma' 并检查是否有 puma 进程正在运行。我的答案中的链接显示了在 nginx 中使用套接字的配置(不确定 apache 是否支持套接字)。
  • 看到 apache 有点痛苦,我现在正在使用 nginx。那么我该怎么做才能开始呢?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-04-07
相关资源
最近更新 更多