简体   繁体   English

“禁止访问” - 乘客,Nginx,Rails

[英]“Access Forbidden” - Passenger, Nginx, Rails

I know there are about 100 questions about this, but after hours of research, I couldn't find my solution. 我知道有大约100个问题,但经过几个小时的研究,我找不到我的解决方案。 Here's my nginx config: 这是我的nginx配置:

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /home/LucyRb/public;
    passenger_enabled on;
    passenger_app_env production;

    index index.html index.htm;
    server_name <domain name>;

    location / {
            try_files $uri $uri/ /index.html;
            passenger_enabled on;
    }
}

My /public directiory: 我的/public指导:

root@Lucy:/var/www/LucyRb/public# namei -l *
f: 404.html
-rwxrwxrwx root root 404.html
f: 422.html
-rwxrwxrwx root root 422.html
f: 500.html
-rwxrwxrwx root root 500.html
f: favicon.ico
-rwxrwxrwx root root favicon.ico
f: robots.txt
-rwxrwxrwx root root robots.txt

I don't think it's a permission problem. 我不认为这是一个许可问题。 I've already run rake db:migrate to create the database, and it worked. 我已经运行了rake db:migrate来创建数据库,并且它有效。 I'm pretty sure environments are set up properly. 我很确定环境设置正确。 All I get is a file listing (since autoindex is on, otherwise I get a 403). 我得到的只是一个文件列表(因为自动索引打开,否则我得到403)。 But routes, nor does the app default index/root, work. 但路由,应用默认索引/根也不起作用。 I've read the Passenger documentation, and I tried troubleshooting with the docs and other SO questions, but I can't seem to get this working. 我已经阅读了Passenger文档,我尝试使用文档和其他SO问题进行故障排除,但我似乎无法使其正常工作。

I haven't forgotten to bundle install and all the proper packages are installed, I'm pretty sure (did I forget any? mysql , rvm and its relevant steps for installing rails, nginx , passenger ... Probably another 2-3). 我没有忘记bundle install和所有正确的软件包安装,我很确定(我忘记了吗? mysqlrvm及其安装rails, nginxpassenger相关步骤......可能另外2-3) 。

I know I'm not supposed to start rails server because it will only allow 1 connection at a time. 我知道我不应该启动rails server因为它一次只允许1个连接。 So nginx is supposed to do that properly, right? 所以nginx应该做得恰到好处,对吧? Or is that what I'm supposed to do with certain flags? 或者这就是我应该用某些标志做的事情?

Thanks in advance. 提前致谢。

Okay everyone. 大家好 With the assistance of Passenger's author on their IRC channel, I was able to resolve the problem. 在乘客的作者IRC频道的帮助下,我能够解决问题。

I had passenger installed twice. 我安装了两次乘客。

From articles I followed that didn't cover the topic thoroughly enough, I was under the assumption Passenger is an installable module of Nginx , which caused me to install Nginx with apt-get , and Passenger via the gems. 从我接下来的文章中我没有详尽地讨论这个话题,我假设PassengerNginx的一个可安装模块,这导致我使用apt-get安装Nginx ,并通过gem安装Passenger

This is an unnecessary redundancy and causes conflicts. 这是不必要的冗余并导致冲突。

Either use only apt-get or only the gems in these cases. 在这些情况下,要么使用apt-get要么使用gems。

passenger-install-nginx-module not only installs a module, it also compiles Nginx from scratch, simply because Nginx is not a modulable application . passenger-install-nginx-module不仅安装了一个模块,还从头开始编译Nginx,因为Nginx不是一个可模块化的应用程序 It is either compiled alongside the module, or doesn't have one at all. 它要么与模块一起编译,要么根本没有。

To sum it up: 把它们加起来:

  1. Only use one method to install Nginx && passenger. 只使用一种方法来安装Nginx && passenger。
  2. Make sure the config points to the right files. 确保配置指向正确的文件。
    I also had a problem with the paths to ruby. 我也遇到了红宝石的问题。 Make sure it points to the wrapper, and not the executable alone: 确保它指向包装器,而不是单独的可执行文件:

     root@Lucy:/usr/local/rvm# which ruby /usr/local/rvm/rubies/ruby-2.0.0-p353/bin/ruby 

    In your config: 在你的配置中:

     passenger_ruby /usr/local/rvm/wrappers/ruby-2.0.0-p353/ruby; 

建议 - 尝试将您的应用程序移动到普通用户可访问的某个位置。例如主目录

How did you install passenger? 你是怎么安装乘客的? With RVM? 使用RVM? RVMSUDO or sudo? RVMSUDO还是sudo? Chances are you shouldn't be using your app as root. 您可能不应该以root身份使用您的应用。 So the permissions on the files aren't allowing passenger to use the rails app. 因此,文件的权限不允许乘客使用rails应用程序。

Assuming your config.ru is in your specified passenger_app_root, try removing your location / {...} directive, restart nginx, and see if your app at least starts up. 假设您的config.ru位于指定的passenger_app_root中,请尝试删除您的location / {...}指令,重新启动nginx,并查看您的应用是否至少启动。 I'm not saying this is the fix, but a troubleshooting measure. 我不是说这是修复,而是一个故障排除措施。

I was going to place this in my comments section but space and formatting are limited so: 我打算将此放在我的评论部分,但空间和格式有限,所以:

I also see you're specifying passenger_enabled twice, which seems unnecessary. 我也看到你两次指定passenger_enabled ,这似乎是不必要的。 I've never seen it turned on in a location directive before, but that might not be your problem. 我之前从未在location指令中看到过它,但这可能不是你的问题。

What do your logs say? 你的日志说什么? You don't seem to have passenger logging/debugging turned on (in http directive): 您似乎没有启用乘客日志记录/调试(在http指令中):

http {
...
    passenger_debug_log_file '/path/to/passenger_debug.log';
    passenger_log_level       5; # default
}

Another thing I'm noticing from your post is that your public directory doesn't seem to contain a rails application?? 我从你的帖子中注意到的另一件事是你的公共目录似乎不包含rails应用程序?

You have 你有

# nginx config
root /home/LucyRb/public;

# shell
/var/www/LucyRb/public

Do you have a correct app in /home/LucyRb? 你在/ home / LucyRb中有正确的应用程序吗? If so, what is the relevance of /var/www/LucyRb? 如果是这样,/ var / www / LucyRb的相关性是什么? If this is a mistake in your config, then it if probably going to cause some trouble! 如果这是你的配置中的错误,那么它可能会导致一些麻烦!

您是否尝试将文件更改为www-data用户?

Every time I've received that error it's been because Nginx wasn't correctly pointing to the passenger gem and executable. 每次我收到该错误都是因为Nginx没有正确指向乘客宝石和可执行文件。 Here's what I suggest, to get things working: 这是我的建议,让事情有效:

  1. Uninstall and/or shut down whatever nginx you've currently got installed. 卸载和/或关闭您当前安装的任何nginx。
  2. cd into your app's root directory, 进入你应用的根目录,
  3. execute the command: passenger-install-nginx-module and let passenger download, compile, and install nginx in /opt . 执行命令: passenger-install-nginx-module ,让乘客在/opt下载,编译和安装nginx。
  4. use the sample config provided by the passenger script for /opt/nginx/conf/nginx.conf . 使用/opt/nginx/conf/nginx.conf的乘客脚本提供的示例配置。
  5. To get the server to start on boot, just add the one line /opt/nginx/sbin/nginx to your /etc/rc.local script . 要让服务器在启动时启动,只需将一行/opt/nginx/sbin/nginx/etc/rc.local script

This recipe has been repeatable and foolproof for me running RVM + Ruby 1.9, 2.0, and Rails 3 and 4 on Ubuntu 10 and 12. 对于我在Ubuntu 10和12上运行RVM + Ruby 1.9,2.0和Rails 3和4,这个方法是可重复的,万无一失。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM