Ruby-on-rails 403 Forbidden on Rails app w/Nginx,Passenger
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19553907/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
403 Forbidden on Rails app w/ Nginx, Passenger
提问by cole
First off, apologies: I know the 403 Forbidden question is a common one for Rails/Nginx installs, but none of the answers I've read so far have solved it for me.
首先,抱歉:我知道 403 Forbidden 问题是 Rails/Nginx 安装的常见问题,但到目前为止我读过的答案都没有为我解决。
Disclaimer: This is my first time deploying a Rails app somewhere that isn't Heroku. Please be gentle. ;)
免责声明:这是我第一次在不是 Heroku 的地方部署 Rails 应用程序。请温柔点。;)
Situation: I have a Rails app running on an Ubuntu 12.04 server, running Nginx (installed with Passenger).
情况:我有一个运行在 Ubuntu 12.04 服务器上的 Rails 应用程序,运行 Nginx(与Passenger 一起安装)。
I've deployed my app to my server correctly, but when I attempt to access the site, I receive a 403 Forbidden error.
我已将我的应用程序正确部署到我的服务器,但是当我尝试访问该站点时,我收到 403 Forbidden 错误。
Checking my error logs, I see:
检查我的错误日志,我看到:
2013/10/23 22:47:01 [error] 27954#0: *105 directory index of "/var/www/colepeters.com/current/public/" is forbidden, client: 50.3…server: colepeters.com, request: "GET / HTTP/1.1", host: "colepeters.com"
2013/10/23 22:47:10 [error] 27954#0: *106 directory index of "/var/www/colepeters.com/current/public/" is forbidden, client: 184…server: colepeters.com, request: "GET / HTTP/1.1", host: "colepeters.com"
2013/10/23 22:47:12 [error] 27954#0: *107 directory index of "/var/www/colepeters.com/current/public/" is forbidden, client: 151…server: colepeters.com, request: "GET / HTTP/1.1", host: "colepeters.com"
However, when checking permissions on this directory, I see that the user I have setup to use Nginx had both read and execute permissions on it.
但是,在检查此目录的权限时,我看到我设置为使用 Nginx 的用户对其具有读取和执行权限。
Here's the relevant info from my nginx.conf:
这是我的 nginx.conf 中的相关信息:
user XXXX;
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 /home/cole/.rvm/gems/ruby-2.0.0-p247/gems/passenger-4.0.21;
passenger_ruby /home/cole/.rvm/wrappers/ruby-2.0.0-p247/ruby;
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name colepeters.com www.colepeters.com;
passenger_enabled on;
root /var/www/colepeters.com/current/public/;
rails_env production;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /var/www/colepeters.com/current/public;
index index.html index.htm;
# autoindex on;
}
I would greatly appreciate any help on resolving this. Thanks!
对于解决此问题的任何帮助,我将不胜感激。谢谢!
UPDATEI have since corrected the erroneus passenger_ruby path, but the 403 Forbidden is persisting, even after restarting Nginx.
更新我已经更正了错误的passenger_ruby路径,但是403 Forbidden仍然存在,即使在重新启动Nginx之后也是如此。
回答by Leandro Figueredo
You can check the path of your passenger installation with
您可以使用以下命令检查乘客安装的路径
passenger-config --root
and the path of your ruby installation with
以及您的 ruby 安装路径
which ruby
then compare with the inserted in nginx.conf.
然后与nginx.conf中插入的比较。
回答by stephanfriedrich
I got the same error. In my case, I fixed it by removing the location / {} entry. - or make sure that your user have permission to your rails project
我得到了同样的错误。就我而言,我通过删除 location / {} 条目来修复它。- 或确保您的用户有权访问您的 rails 项目
...
server {
listen 80;
server_name 127.0.0.1;
passenger_enabled on;
rails_env production;
root /www/kalender/public ;
#charset koi8-r;
access_log /var/log/nginx/host.access.log;
#location / {
#root html;
#index index.html index.htm;
#}
回答by ethicalhack3r
Adding passenger_enabled on;to the server directive worked for me.
添加passenger_enabled on;到服务器指令对我有用。
回答by Sam M.
I was running a similar setup to yours and having the same problem with my nginx.conf file. Stumbling across the Nginx pitfalls pagehelped me solve it.
我正在运行与您类似的设置,并且我的 nginx.conf 文件也有同样的问题。偶然发现Nginx 陷阱页面帮助我解决了它。
Your file looks similar to mine, so I'll share two things you may want to try that worked for me:
您的文件看起来与我的相似,因此我将分享您可能想尝试的对我有用的两件事:
first, you have the
rootpath in both theserver {}block AND thelocation {}block. While not necessarily a problem, according to the docs linked above "If you add a root to every location block then a location block that isn't matched will have no root." I got rid of the roots in the location blocks but kept it in the server block.move the 'index' directives (
index index.html index.htm;) out of the location block up to within thehttp {}block. The location blocks will inherit from this.
首先,您
root在server {}块和location {}块中都有路径。虽然不一定是一个问题,但根据上面链接的文档“如果您向每个位置块添加一个根,那么不匹配的位置块将没有根。” 我摆脱了位置块中的根,但将其保留在服务器块中。将“索引”指令 (
index index.html index.htm;) 从位置块移到http {}块内。位置块将从这里继承。
doing those two things and restarting the server worked for me.
做这两件事并重新启动服务器对我有用。
回答by Jxtps
The problem lies in the location / {...}section: the passenger_enabled ondoesn't propagate from the server {...}into the location / {...}.
问题在于location / {...}部分:passenger_enabled on不会从 传播server {...}到location / {...}.
If you either remove location / {...}, or add passenger_enabled onto it, it should work.
如果您删除location / {...}或添加passenger_enabled on它,它应该可以工作。
回答by Vitaliy LiBrus
you also have config-file for passenger called passenger.confby default in /etc/nginx/conf.d/passenger.confthere you have to put correct roots.
you can check the roots with these two commands
您还有passenger.conf默认情况下调用的乘客配置文件,/etc/nginx/conf.d/passenger.conf您必须在其中放置正确的根。您可以使用这两个命令检查根
passenger-config --root
and
和
which ruby
哪个红宝石
so when you get these roots you have to compare them with such in your passenger.conffile and it can be e.g. smth like this
因此,当您获得这些根时,您必须将它们与passenger.conf文件中的根进行比较,并且可以像这样
#passenger-config --root
passenger_root /usr/share/ruby/vendor_ruby/phusion_passenger/locations.ini;
#which ruby
passenger_ruby /usr/local/rvm/rubies/ruby-2.4.0/bin/ruby;
passenger_instance_registry_dir /var/run/passenger-instreg;
so if you use this way don't forget to make in http section of your nginx.conf
因此,如果您使用这种方式,请不要忘记在您的 http 部分 nginx.conf
include /etc/nginx/conf.d/passenger.conf
as well as inserting in server section
以及插入服务器部分
passenger_enabled on;
回答by sam.ruby
The key things are: Remove the location block for the / section, assuming that the Rails application is accessible at /
关键是: 删除 / 部分的位置块,假设 Rails 应用程序可在 /
Ensure the passenger_ruby is pointing to the rvm wrapper script for the selected ruby version
确保passenger_ruby 指向所选ruby 版本的rvm 包装器脚本
Add execute permissions to user, group and others to all the directories reaching to
将用户、组和其他人的执行权限添加到所有目录中
/var/www/rails_app/public folder
/var
/var/www
/var/www/rails_app
/var/www/rails_app/public_foler
回答by iniy
You are declaring the root twice inside the server block and inside the /location block as well as directing nginx to use the index directive. Also remove the "/" after public folder
您在 server 块内和 /location 块内两次声明根,并指示 nginx 使用 index 指令。还要删除公用文件夹后的“/”
try doing this
尝试这样做
user XXXX;
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 /home/cole/.rvm/gems/ruby-2.0.0-p247/gems/passenger-4.0.21;
passenger_ruby /home/cole/.rvm/wrappers/ruby-2.0.0-p247/ruby;
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name colepeters.com www.colepeters.com;
passenger_enabled on;
root /var/www/colepeters.com/current/public;
rails_env production;
#charset koi8-r;
#access_log logs/host.access.log main;
}
}

