简体   繁体   中英

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. For deployment purpose I have created deployer user.

I've installed ruby/rails/passenger using rvm.

My /opt/nginx/conf/nginx.conf is as below:

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. And error.log is as follows:

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:

After connecting to server, unless I do

$ source ~/.bash_profile

I see my rails version as 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.

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. So it simply sources .bashrc but not .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

Here is the reference for the explanation I found on unix.stackexchange.

Apparently I had messed up something by referencing multiple documentations available on 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 :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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