Rails 使用 Capistrano 部署到 EC2 后应用程序未加载
Rails application not loading after deploy to EC2 using Capistrano
我设置了一个 Amazon EC2 Ubuntu 14.04 实例,并按照 Passenger website 中的指南在 Apache 中使用 Capistrano 和 Passenger 部署了我的 Rails 应用程序,尝试遵循所有说明,除了我有不同的应用程序名称和目录:/var/www/<my_app_name>
。
经过一些配置后,部署终于成功,当我在我的应用程序文件夹中尝试 运行 Rails 控制台时,它工作正常,但是当我尝试通过 Web 浏览器中的 IP 地址访问我的应用程序时它根本不加载,浏览器返回 ERR_CONNECTION_TIMED_OUT 错误。我已经多次重启 Apache,但它仍然无法正常工作。 Apache/Passenger.
可能遗漏了某些内容或配置错误
这是我的 Apache 错误日志,来自 /var/log/apache2/error.log
:
[ 2015-11-24 14:20:25.7238 18152/7f3199f9d700 Ser/Server.h:444 ]: [UstRouter] Shutdown finished
[ 2015-11-24 14:20:25.7239 18152/7f31a07ab7c0 age/Ust/UstRouterMain.cpp:498 ]: Passenger UstRouter shutdown finished
[ 2015-11-24 14:20:25.7306 18230/7f2bca98a7c0 age/Wat/WatchdogMain.cpp:1276 ]: Starting Passenger watchdog...
[ 2015-11-24 14:20:25.7394 18233/7f7e579cd7c0 age/Cor/CoreMain.cpp:957 ]: Starting Passenger core...
[ 2015-11-24 14:20:25.7395 18233/7f7e579cd7c0 age/Cor/CoreMain.cpp:234 ]: Passenger core running in multi-application mode.
[ 2015-11-24 14:20:25.7408 18233/7f7e579cd7c0 age/Cor/CoreMain.cpp:707 ]: Passenger core online, PID 18233
[ 2015-11-24 14:20:25.7463 18242/7f9e135ba7c0 age/Ust/UstRouterMain.cpp:504 ]: Starting Passenger UstRouter...
[ 2015-11-24 14:20:25.7469 18242/7f9e135ba7c0 age/Ust/UstRouterMain.cpp:317 ]: Passenger UstRouter online, PID 18242
[Tue Nov 24 14:20:25.747329 2015] [mpm_event:notice] [pid 17566:tid 139962846635904] AH00489: Apache/2.4.7 (Ubuntu) Phusion_Passenger/5.0.21 configured -- resuming normal operations
[Tue Nov 24 14:20:25.747348 2015] [core:notice] [pid 17566:tid 139962846635904] AH00094: Command line: '/usr/sbin/apache2'
而我的 access.log 是空的。
这是我在 /etc/apache2/sites-enabled/my_app.conf
中的 Apache 应用程序配置:
<VirtualHost *:80>
ServerName <my_ip_address>
# Tell Apache and Passenger where your app's 'public' directory is
DocumentRoot /var/www/my_app/current/public
PassengerRuby /usr/local/rvm/rubies/ruby-2.2.1/bin/ruby
# Relax Apache security settings
<Directory /var/www/my_app/current/public>
Allow from all
Options -MultiViews
Require all granted
</Directory>
</VirtualHost>
非常感谢任何帮助。提前致谢。
更新 1:
当我尝试使用 passenger-status
:
查看 Passenger 的状态时
Phusion Passenger is currently not serving any applications.
我试图通过触摸 restart.txt
来让我的应用程序连接到 Passenger:
$sudo touch /var/www/my_app/current/tmp/restart.txt
但它不起作用。
问题出在 this SO question 中指出的实例设置上。默认情况下,EC2 实例不允许 public HTTP 访问:
单击 ec2 页面导航选项卡中的实例
滚动浏览您的实例记录以查找安全组。点击安全组。
Select 安全组的“入站”选项卡并确保存在以下规则。
HTTP TCP 80 0.0.0.0/0
我设置了一个 Amazon EC2 Ubuntu 14.04 实例,并按照 Passenger website 中的指南在 Apache 中使用 Capistrano 和 Passenger 部署了我的 Rails 应用程序,尝试遵循所有说明,除了我有不同的应用程序名称和目录:/var/www/<my_app_name>
。
经过一些配置后,部署终于成功,当我在我的应用程序文件夹中尝试 运行 Rails 控制台时,它工作正常,但是当我尝试通过 Web 浏览器中的 IP 地址访问我的应用程序时它根本不加载,浏览器返回 ERR_CONNECTION_TIMED_OUT 错误。我已经多次重启 Apache,但它仍然无法正常工作。 Apache/Passenger.
可能遗漏了某些内容或配置错误这是我的 Apache 错误日志,来自 /var/log/apache2/error.log
:
[ 2015-11-24 14:20:25.7238 18152/7f3199f9d700 Ser/Server.h:444 ]: [UstRouter] Shutdown finished
[ 2015-11-24 14:20:25.7239 18152/7f31a07ab7c0 age/Ust/UstRouterMain.cpp:498 ]: Passenger UstRouter shutdown finished
[ 2015-11-24 14:20:25.7306 18230/7f2bca98a7c0 age/Wat/WatchdogMain.cpp:1276 ]: Starting Passenger watchdog...
[ 2015-11-24 14:20:25.7394 18233/7f7e579cd7c0 age/Cor/CoreMain.cpp:957 ]: Starting Passenger core...
[ 2015-11-24 14:20:25.7395 18233/7f7e579cd7c0 age/Cor/CoreMain.cpp:234 ]: Passenger core running in multi-application mode.
[ 2015-11-24 14:20:25.7408 18233/7f7e579cd7c0 age/Cor/CoreMain.cpp:707 ]: Passenger core online, PID 18233
[ 2015-11-24 14:20:25.7463 18242/7f9e135ba7c0 age/Ust/UstRouterMain.cpp:504 ]: Starting Passenger UstRouter...
[ 2015-11-24 14:20:25.7469 18242/7f9e135ba7c0 age/Ust/UstRouterMain.cpp:317 ]: Passenger UstRouter online, PID 18242
[Tue Nov 24 14:20:25.747329 2015] [mpm_event:notice] [pid 17566:tid 139962846635904] AH00489: Apache/2.4.7 (Ubuntu) Phusion_Passenger/5.0.21 configured -- resuming normal operations
[Tue Nov 24 14:20:25.747348 2015] [core:notice] [pid 17566:tid 139962846635904] AH00094: Command line: '/usr/sbin/apache2'
而我的 access.log 是空的。
这是我在 /etc/apache2/sites-enabled/my_app.conf
中的 Apache 应用程序配置:
<VirtualHost *:80>
ServerName <my_ip_address>
# Tell Apache and Passenger where your app's 'public' directory is
DocumentRoot /var/www/my_app/current/public
PassengerRuby /usr/local/rvm/rubies/ruby-2.2.1/bin/ruby
# Relax Apache security settings
<Directory /var/www/my_app/current/public>
Allow from all
Options -MultiViews
Require all granted
</Directory>
</VirtualHost>
非常感谢任何帮助。提前致谢。
更新 1:
当我尝试使用 passenger-status
:
Phusion Passenger is currently not serving any applications.
我试图通过触摸 restart.txt
来让我的应用程序连接到 Passenger:
$sudo touch /var/www/my_app/current/tmp/restart.txt
但它不起作用。
问题出在 this SO question 中指出的实例设置上。默认情况下,EC2 实例不允许 public HTTP 访问:
单击 ec2 页面导航选项卡中的实例
滚动浏览您的实例记录以查找安全组。点击安全组。
Select 安全组的“入站”选项卡并确保存在以下规则。
HTTP TCP 80 0.0.0.0/0