使用 Nginx 启动 Passenger 时出现问题
我刚刚使用 Nginx 设置了 Passenger,它似乎安装得很好,但是当我运行它时,我尝试通过以下方式启动它:
passenger start -e production
我得到:
=============== Phusion Passenger Standalone web server started ===============
PID file: /root/rails_apps/myapp/tmp/pids/passenger.3000.pid
Log file: /root/rails_apps/myapp/log/passenger.3000.log
Environment: production
Accessible via: http://0.0.0.0:3000/
You can stop Phusion Passenger Standalone by pressing Ctrl-C.
===============================================================================
2011/04/18 07:17:27 [error] 9125#0: *4 "/root/rails_apps/myapp/public/index.html" is forbidden (13: Permission denied), client: 127.0.0.1, server: _, request: "HEAD / HTTP/1.1", host: "0.0.0.0"
当我尝试在浏览器中访问我的网站时,我得到“无法连接”。
这是 nginx.conf 中的配置
server {
listen 80;
server_name myapp.com;
root /root/rails_apps/myapp/public; # <--- be sure to point to 'public'!
passenger_enabled on;
}
有什么想法吗?
I have just setup Passenger with Nginx and it seems to install fine but when I run it I try to start it by:
passenger start -e production
I get:
=============== Phusion Passenger Standalone web server started ===============
PID file: /root/rails_apps/myapp/tmp/pids/passenger.3000.pid
Log file: /root/rails_apps/myapp/log/passenger.3000.log
Environment: production
Accessible via: http://0.0.0.0:3000/
You can stop Phusion Passenger Standalone by pressing Ctrl-C.
===============================================================================
2011/04/18 07:17:27 [error] 9125#0: *4 "/root/rails_apps/myapp/public/index.html" is forbidden (13: Permission denied), client: 127.0.0.1, server: _, request: "HEAD / HTTP/1.1", host: "0.0.0.0"
and I get "Unable to connect" when I try to access my site in the browser.
Here is configuration in nginx.conf
server {
listen 80;
server_name myapp.com;
root /root/rails_apps/myapp/public; # <--- be sure to point to 'public'!
passenger_enabled on;
}
any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这个错误似乎是由于 nginx 用户无法访问上述文件而引起的。不仅 /root/rails_apps/myapp/public 没有正确的权限,而且即使父目录之一没有正确的权限也会导致这种情况!
在 nginx.conf 中,您可以看到类似以下内容:
有时
user
的参数可能不同。确保路径中的所有文件夹可供该用户使用。您可以通过 sudo -Hu nginx /bin/bash -l 和 cat /root/rails_apps/myapp/public/index.html 来检查。使用此命令反复测试,直到看不到文件内容。
一点解释:使用 sudo 命令,您可以以用户 nginx 身份启动 shell。并且使用
cat
命令可以模拟文件读取。This error seems caused because the user of nginx cannot access the mentioned file. It can be caused not only if the /root/rails_apps/myapp/public is not have a correct permission, but even if one of the parent directories does not have that!
In your nginx.conf you can see something like:
Sometimes parameter of the
user
can be different. Be sure to all folder is available by this user in the path.You can check it by
sudo -Hu nginx /bin/bash -l
andcat /root/rails_apps/myapp/public/index.html
. Test and test it again with this command until you cannot see the content of the file.A little explanation: with that sudo command you start a shell as an user nginx. And with
cat
command you can simulate the file reading.试试这个:
Try this:
由于您指定的路径位于 /root (/root/rails_apps/myapp/public) 中,因此 nginx 应该具有足够的权限:
user root
;在 nginx.conf 中,您还应该以超级用户( sudo )身份启动 nginx,
但最好将您的 Rails 应用程序移至用户目录的某个位置,并向默认 nginx 用户“www-data”授予所需的权限
since the path you specified is in /root (/root/rails_apps/myapp/public), nginx should have enough permissions:
user root
; in nginx.confyou should also start nginx as superuser ( sudo )
but it might be better to just move your rails app somewhere to your user directory and grant needed permissions to default nginx user 'www-data'