以下是我在我的nginx.conf中拥有的内容:
#user nobody;
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/lib/ruby/gems/1.9.1/gems/passenger-3.0.11;
passenger_ruby /usr/bin/ruby;
include mime.types;
default_type application/octet-stream;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
gzip on;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plain text/html text/css
application/x-javascript text/xml
application/xml application/xml+rss
text/javascript;
server {
listen 80;
server_name domain.com www.domain.com;
# autoindex on;
passenger_enabled on;
rails_env production;
access_log logs/mrfs.access.log;
location / {
root /opt/nginx/html/mrfs/public; #line updated per suggestion below
}
}
}我可以打开和关闭自动索引,当它被注释掉时,它会显示一个403错误,或者当它打开时显示一个目录列表。当我访问目录清单时,我可以浏览它们并下载各种文件。在我看来,这似乎不是一个权限问题。当我禁用自动索引时,我会在错误日志中得到一个无法列出的目录错误。我想我需要做的是告诉nginx如何加载我的index.html.erb文件?我该怎么做?这就是问题所在吗?
更新
我在我的/opt/nginx/html/mrfs/公用文件夹中放了一个'index.html‘,它会加载它。那么,是什么原因导致rails/nginx/ file公开加载index.html文件,而不是在我的路由中加载home.html.erb文件呢?我可以运行'rails‘,然后做一个wget http://localhost,然后它会拉下正确的html文件。
发布于 2011-12-08 17:27:45
以下是我必须将其更改为:
server {
listen 80;
server_name domain.com www.domain.com;
rails_env production;
passenger_use_global_queue on;
access_log logs/mrfs.access.log;
root /opt/nginx/html/mrfs/public;
passenger_enabled on;
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
}
}如果在您的location /中有一个nginx.conf,那么您必须打开passenger_enabled;否则就删除location /块。我选择删除它。
发布于 2011-12-07 22:19:04
您需要将root设置为项目的public目录:
server {
...
passenger_enabled on;
rails_env production;
root /opt/nginx/html/mrfs/public;
}发布于 2011-12-07 23:50:36
除了另一个答案中的“公用”文件夹更正外,在我看来,包含应用程序的文件夹的权限/所有权存在问题。nginx.conf里应该有一条线就像.
user websrv;它定义了nginx自己运行的用户。您的rails应用程序的文件夹应该由该用户拥有,权限应该被适当设置。
https://stackoverflow.com/questions/8423391
复制相似问题