使用 Nginx 启动 Passenger 时出现问题

发布于 2024-11-02 00:23:36 字数 1034 浏览 2 评论 0原文

我刚刚使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

残龙傲雪 2024-11-09 00:23:36

这个错误似乎是由于 nginx 用户无法访问上述文件而引起的。不仅 /root/rails_apps/myapp/public 没有正确的权限,而且即使父目录之一没有正确的权限也会导致这种情况!

在 nginx.conf 中,您可以看到类似以下内容:

user nginx;

http {
    # blah.
}

有时 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:

user nginx;

http {
    # blah.
}

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 and cat /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.

指尖上得阳光 2024-11-09 00:23:36

试试这个:

sudo passenger start -e production

Try this:

sudo passenger start -e production
友谊不毕业 2024-11-09 00:23:36

由于您指定的路径位于 /root (/root/rails_apps/myapp/public) 中,因此 nginx 应该具有足够的权限:

user root;在 nginx.conf 中,

您还应该以超级用户( sudo )身份启动 nginx,

但最好将您的 Rails 应用程序移至用户目录的某个位置,并向默认 nginx 用户“www-data”授予所需的权限

user www-data;

since the path you specified is in /root (/root/rails_apps/myapp/public), nginx should have enough permissions:

user root; in nginx.conf

you 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'

user www-data;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文