简体   繁体   English

Rails 4.1.6 APP:NGINX:目录索引“ / var / www / your_own_store / current / public /”被禁止

[英]Rails 4.1.6 APP: NGINX: directory index of “/var/www/your_own_store/current/public/” is forbidden

I'm trying to deploy a rails application on linode VPS. 我正在尝试在linode VPS上部署Rails应用程序。 For deployment purpose I have created deployer user. 为了进行部署,我创建了deployer用户。

I've installed ruby/rails/passenger using rvm. 我已经使用rvm安装了ruby / rails / passenger。

My /opt/nginx/conf/nginx.conf is as below: 我的/opt/nginx/conf/nginx.conf如下:

http {
passenger_root /home/deployer/.rvm/gems/ruby-2.1.3/gems/passenger-4.0.52;
passenger_ruby /home/deployer/.rvm/rubies/ruby-2.1.3/bin/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;
server {
    listen       80;
    server_name  myserver;
    passenger_enabled on;
    rails_env production;
    root /var/www/your_own_store/current/public;
    #charset koi8-r;

    #access_log  logs/host.access.log  main;

After nginx restart I'm getting 403 page. 在重启nginx之后,我得到了403页。 And error.log is as follows: 而error.log如下:

2014/09/30 13:33:24 [error] 27388#0: *27 directory index of "/var/www/your_own_store/current/public/" is forbidden, client: 1.39.62.158, server: myserver, request: "GET / HTTP/1.1", host: "myhost"

After debugging for almost 2 days, I feel the issue might be because of this: 经过将近2天的调试,我认为问题可能是由于以下原因:

After connecting to server, unless I do 连接到服务器后,除非我这样做

$ source ~/.bash_profile

I see my rails version as 1.9.3. 我看到我的rails版本是1.9.3。 And passenger installed at different place as shown below: 与乘客安装在不同的地方,如下图所示:

root@localhost:/opt/nginx/logs# passenger-config --root
/var/lib/gems/1.9.1/gems/passenger-4.0.52
root@localhost:/opt/nginx/logs# su deployer
deployer@localhost:/opt/nginx/logs$ passenger-config --root
/var/lib/gems/1.9.1/gems/passenger-4.0.52
deployer@localhost:/opt/nginx/logs$ source ~/.bashrc
deployer@localhost:/opt/nginx/logs$ passenger-config --root
/var/lib/gems/1.9.1/gems/passenger-4.0.52
deployer@localhost:/opt/nginx/logs$ source ~/.bash_profile
deployer@localhost:/opt/nginx/logs$ passenger-config --root
/home/deployer/.rvm/gems/ruby-2.1.3/gems/passenger-4.0.52

root@localhost:/opt/nginx/conf# ruby -v
ruby 1.9.3p484 (2013-11-22 revision 43786) [x86_64-linux]
root@localhost:/opt/nginx/conf# su deployer
deployer@localhost:/opt/nginx/conf$ ruby -v
ruby 1.9.3p484 (2013-11-22 revision 43786) [x86_64-linux]
deployer@localhost:/opt/nginx/conf$ source ~/.bash_profile
deployer@localhost:/opt/nginx/conf$ ruby -v
ruby 2.1.3p242 (2014-09-19 revision 47630) [x86_64-linux]

I'm not sure if this is the root cause of the issue. 我不确定这是否是问题的根本原因。 If it is so, how to fix it? 如果是这样,如何解决?

Earlier I had everything installed as root and it was working like charm. 早些时候,我以root身份安装了所有内容,并且它像魅力一样工作。

Can anyone please help me on this? 有人可以帮我吗?

Thanks 谢谢

UPDATE: I could find the solution for default ruby setup. 更新:我可以找到默认红宝石设置的解决方案。 The reason is, while logging in as a user, system sources .bash_profile, whereas if I do 'su', its non-login shell. 原因是,以用户身份登录时,系统源.bash_profile,而如果我执行“ su”,则为非登录外壳。 So it simply sources .bashrc but not .bash_profile. 因此,它只是来源.bashrc而不是.bash_profile。

So after adding following line to .bashrc, I can find the correct ruby version after 'su' [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session as a function 因此,在将以下行添加到.bashrc之后,我可以在'su'[[-s“ $ HOME / .rvm / scripts / rvm”]] &&源“ $ HOME / .rvm / scripts / rvm”之后找到正确的Ruby版本#将RVM 作为功​​能加载到Shell会话

Here is the reference for the explanation I found on unix.stackexchange. 是我在unix.stackexchange上找到的解释的参考。

Apparently I had messed up something by referencing multiple documentations available on web. 显然,我通过引用Web上提供的多个文档弄乱了一些东西。 I simply rebuilt the server and followed the right steps(I'll be posting all the steps in blog soon). 我只是简单地重建了服务器并遵循正确的步骤(很快我将在博客中发布所有步骤)。 All working like charm :) 所有的工作都像魅力:)

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

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