我已经尝试了超过一天的时间让Nginx和Passenger为我的Rails应用程序工作,但我得到的只是:Nginx欢迎页面。为什么呢?
我已将Nginx安装在默认位置/opt/nginx
,如下所示:
# Install passenger gem
$ gem install passenger
# Install dependencies for Nginx/Passenger
$ apt-get install libcurl4-openssl-dev
# Compile it
$ passenger-install-nginx-module
文件/opt/nginx/conf/nginx.conf
的(我认为)相关部分如下所示:
http {
passenger_root /usr/local/rvm/gems/ruby-2.0.0-p353/gems/passenger-4.0.29;
passenger_ruby /usr/local/rvm/wrappers/ruby-2.0.0-p353/ruby;
server {
listen 80;
server_name www.my-domain.com;
root /home/deploy/current/public;
passenger_enabled on;
location / {
root html;
index index.html index.htm;
passenger_enabled on;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
passenger_enabled on;
}
...
当我检查“根位置”(公共)时,我可以看到应用程序在那里(它与Capistrano一起部署):
$ ls /home/deploy/current/public
404.html 422.html 500.html assets css favicon.ico js robots.txt system
...或1级以上:
$ ls /home/deploy/current
app Capfile config.ru doc Gemfile.lock log public resque.pid script tmp
assets_manifest.yml config db Gemfile lib LOG Rakefile REVISION test vendor
看看Rails production.log,我可以看到它从未超越编译资产:
$ tail -f /home/deploy/current/log/production.log
Compiled page_specific/some_file_5.css (137ms) (pid 28316)
Compiled page_specific/some_file_4.css (19ms) (pid 28316)
Compiled page_specific/some_file_3.css (3ms) (pid 28316)
Compiled page_specific/some_file_2.css (3ms) (pid 28316)
Compiled page_specific/some_file_1.css (16ms) (pid 28316)
Compiled application.css (3131ms) (pid 28316)
查看Nginx error.log,我看不出任何错误(正常访问URL(“主页”)似乎没有创建任何条目):
$ tail -f /opt/nginx/logs/error.log
查看Nginx access.log,我看不出任何错误(正常访问URL(“主页”)似乎没有创建任何条目):
$ tail -f /opt/nginx/logs/error.log
[ 2013-12-29 01:16:55.6792 2099/7fa534fca740 agents/Watchdog/Main.cpp:697 ]: All Phusion Passenger agents started!
此外:
#access_log logs/access.log main;
而不取消注释#log_format main
,则会抱怨)这里可能有什么问题?
答案 0 :(得分:12)
圣洁的。显然需要使其发挥作用的是:
注释掉/删除在安装过程中默认添加的“location /”指令:
# location / {
# root html;
# index index.html index.htm;
# passenger_enabled on;
# }
(如果有人知道原因,我有兴趣知道。)