Rails + Passenger + Nginx:第二个应用程序“404 Not Found”

Rails + Passenger + Nginx: "404 Not Found" for second app

我正在尝试将第二个应用程序部署到 Digital Ocean。

我通过本教程成功部署了第一个应用程序:https://www.phusionpassenger.com/library/walkthroughs/deploy/ruby/digital_ocean/integration_mode.html

我按照相同的教程在同一个地方添加了第二个应用程序。当我尝试访问第二个应用程序时,我收到消息“404 Not Found”并且日志显示:

2021/08/09 11:39:43 [error] 43452#43452: *21 "/var/www/philosophische_insel/public/index.html" is not found (2: No such file or directory)

有针对此确切问题的故障排除指南:https://www.phusionpassenger.com/docs/advanced_guides/troubleshooting/nginx/troubleshooting/node/

这是我到目前为止尝试过的:

到“原因和解决方案#1”

我添加了“passenger_enabled;”:

#cat /etc/nginx/sites-enabled/philosophische_insel.conf 
server {
    listen 80;
    server_name philosophische-insel.ch www.philosophische-insel.ch;

# Tell Nginx and Passenger where your app's 'public' directory is
root /var/www/philosopische_insel/public;

# Turn on Passenger
passenger_enabled on;
passenger_ruby /home/sandro/.rvm/gems/ruby-3.0.0/wrappers/ruby;
}

到“原因和解决方案#2”

passenger_root 设置为:/usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;

cat /etc/nginx/conf.d/mod-http-passenger.conf
### Begin automatically installed Phusion Passenger config snippet ###
passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
passenger_ruby /usr/bin/passenger_free_ruby;
### End automatically installed Phusion Passenger config snippet ###

passenger-config --root

的结果相同
/usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini

至“原因和解决方案 #3” 我试图找出一些错误,但没有成功。

当我重新加载 nginx 并检查 error.log 时,我得到这个:

[ N 2021-08-09 12:10:57.2432 44738/T1 age/Wat/WatchdogMain.cpp:1373 ]: Starting Passenger watchdog...
[ N 2021-08-09 12:10:57.2904 44741/T1 age/Cor/CoreMain.cpp:1340 ]: Starting Passenger core...
[ N 2021-08-09 12:10:57.2905 44741/T1 age/Cor/CoreMain.cpp:256 ]: Passenger core running in multi-application mode.
[ N 2021-08-09 12:10:57.3033 44741/T1 age/Cor/CoreMain.cpp:1015 ]: Passenger core online, PID 44741
[ N 2021-08-09 12:10:59.4811 44741/T5 age/Cor/SecurityUpdateChecker.h:519 ]: Security update check: no update found (next check in 24 hours)
2021/08/09 12:11:03 [error] 44756#44756: *1 "/var/www/philosopische_insel/public/index.html" is not found (2: No such file or directory), client: 87.245.104.21, server: philosophische-insel.ch, request: "GET / HTTP/1.1", host: "www.philosophische-insel.ch"

passenger-status只显示第一个app

我不知道它是否重要,但 passenger-status 只显示应用程序组中的第一个应用程序,而不显示第二个应用程序:

----------- General information -----------
Max pool size : 6
App groups    : 1
Processes     : 1
Requests in top-level queue : 0

----------- Application groups -----------
/var/www/dialectica (production):
  App root: /var/www/dialectica
  Requests in queue: 0
  * PID: 45528   Sessions: 0       Processed: 1       Uptime: 1m 57s
    CPU: 0%      Memory  : 34M     Last used: 1m 57s ago

更多信息

第一个应用成功了。但是它有一个不同的 ruby 版本。这是一个比较:

Ruby版本:

第一个应用程序:

ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-linux]

第二个应用:

ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-linux]

Nginx-配置

第一个应用程序:

server {
    listen 80;
    server_name 159.65.120.231;

    # Tell Nginx and Passenger where your app's 'public' directory is
    root /var/www/dialectica/public;

    # Turn on Passenger
    passenger_enabled on;
    passenger_ruby /home/sandro/.rvm/gems/ruby-2.6.3/wrappers/ruby;
}

第二个应用:

server {
    listen 80;
    server_name philosophische-insel.ch www.philosophische-insel.ch;

    # Tell Nginx and Passenger where your app's 'public' directory is
    root /var/www/philosopische_insel/public;

    # Turn on Passenger
    passenger_enabled on;
    passenger_ruby /home/sandro/.rvm/gems/ruby-3.0.0/wrappers/ruby;
}

有什么想法吗?

在这一点上,我不知道如何进行。有什么想法吗?

假设这两个应用都运行良好,我有三个建议:

  1. 保留您的 root 语句并添加 passenger_app_root 与您的真实应用程序根路径而不是它们的 public 路径
  2. 在您的第一个应用程序配置中,您说的是:“将寻找 159.65.120.231:80 的每个请求重定向到 dialecta 路径”,但问题是您的 DNS 也解析 philosophische-insel.ch159.65.120.231:80。所以你永远无法访问你的第二个应用程序。尝试在每个应用的配置中使用不同的端口或不同的域(或子域)
  3. 记得经常用 sudo nginx -t 检查你的 Nginx 配置,如果 配置没问题,用 sudo service nginx reload
  4. 重启 Nginx

因此,以下可能是您服务器的一种配置:

server {
    ## Any of the followings should work

    ## Option 1: use a subdomain for this, remember that your DNS must be
    ## redirecting subdomains to this IP
    listen 80;
    server_name dialecta.philosophische-insel.ch www.dialecta.philosophische-insel.ch;

    ## Option 2: use a different domain. Also needs DNS config
    # listen 80;
    # server_name dialecta.ch www.dialecta.ch;

    ## Option 3: use a different port ##
    # listen 81;
    # server_name 159.65.120.231;

    passenger_enabled on;
    passenger_app_root /var/www/dialectica;
    passenger_ruby /home/sandro/.rvm/gems/ruby-2.6.3/wrappers/ruby;

    root /var/www/dialectica/public;
}
server {
    listen 80;
    server_name philosophische-insel.ch www.philosophische-insel.ch;

    passenger_enabled on;
    passenger_app_root /var/www/philosopische_insel;
    passenger_ruby /home/sandro/.rvm/gems/ruby-3.0.0/wrappers/ruby;

    root /var/www/philosopische_insel/public;
}

如果您不断出错,请post输出sudo nginx -t