简体   繁体   English

nginx错误/ home / deploy / myapp / current / public /“被禁止

[英]nginx error /home/deploy/myapp/current/public/" is forbidden

I tried the solution of a similar question and many other on stackoverflow but none of them seem to solve this issue. 我尝试了一个类似问题的解决方案以及其他许多关于stackoverflow的解决方案,但是似乎都没有一个解决方案。 The default niginx "Welcome" page was running even when I configured /etc/nginx/passenger.conf and /etc/nginx/passenger.conf . 即使配置了/etc/nginx/passenger.conf/etc/nginx/passenger.conf ,默认的niginx“欢迎”页面仍在运行。 It was after I configured the /etc/nginx/sites-enabled/default , by changing the default path to my rails app, I started getting 403 forbidden error. 在我配置了/ etc / nginx / sites-enabled / default之后 ,通过更改我的rails应用程序的默认路径,我开始收到403禁止错误。

This is the error log. 这是错误日志。

2017/02/20 06:05:17 [error] 27311#27311: *2 directory index of "/home/deploy/Blog/current/public/" is forbidden, client: 111.93.247.206, server: mydomain.com, request: "GET / HTTP/1.1", host: "35.154.168.57"

My nginx files are as follows. 我的nginx文件如下。

/etc/nginx/nginx.conf /etc/nginx/nginx.conf

user deploy;
worker_processes auto;
pid /run/nginx.pid;

events {
        worker_connections 768;
        # multi_accept on;
}

http {

        ##
        # Basic Settings
        ##

        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        # server_tokens off;

        # server_names_hash_bucket_size 64;
        # server_name_in_redirect off;

        include /etc/nginx/mime.types;
        default_type application/octet-stream;

        ##
        # SSL Settings
        ##

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
        ssl_prefer_server_ciphers on;

        ##
        # Logging Settings
        ##

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;

        ##
        # Gzip Settings
        ##


gzip on;
        gzip_disable "msie6";

        # gzip_vary on;
        # gzip_proxied any;
        # gzip_comp_level 6;
        # gzip_buffers 16 8k;
        # gzip_http_version 1.1;
        # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

        ##
        # Phusion Passenger config
        ##
        # Uncomment it if you installed passenger or passenger-enterprise
        ##

        # include /etc/nginx/passenger.conf;

        ##
        # Virtual Host Configs
        ##

        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;
}


#mail {
#       # See sample authentication script at:
#       # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
#       # auth_http localhost/auth.php;
#       # pop3_capabilities "TOP" "USER";
#       # imap_capabilities "IMAP4rev1" "UIDPLUS";
#
#       server {
#               listen     localhost:110;
#               protocol   pop3;
#               proxy      on;

/etc/nginx/passenger.conf /etc/nginx/passenger.conf

passenger_ruby /home/deploy/.rvm/wrappers/ruby-2.3.1/ruby;
passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
#passenger_ruby /usr/bin/passenger_free_ruby;

/etc/nginx/sites-enabled/default 在/ etc / nginx的/启用的站点- /默认

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

        server_name mydomain.com;
        passenger_enabled on;
        rails_env    production;
        root         /home/deploy/Blog/current/public;

        # redirect server error pages to the static page /50x.html
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
}

The permissions are: 权限是:

lrwxrwxrwx 1 root root 34 Feb 20 06:00 /etc/nginx/sites-enabled/default 
-rw-r--r-- 1 root root 179 Feb 20 06:35 /etc/nginx/passenger.conf
-rw-r--r-- 1 root root 1608 Feb 20 06:34 /etc/nginx/nginx.conf

Please can somebody tell what am I doing wrong or what have I not done? 请可以告诉别人我在做什么错或我没有做什么吗? Thank You 谢谢

Follow these steps: 跟着这些步骤:

  1. Backup /home/deploy/Blog/current/public 备份/ home / deploy / Blog / current / public
  2. chown -R <nginxuser>:<nginxuser> /home/deploy/Blog/current/public

nginxuser : the user that runs nginx, its probably one of the following: nginx , www-data , root . nginxuser :运行nginx的用户,可能是以下之一: nginxwww-dataroot

Not sure what exactly you missing. 不知道你到底错过了什么。 Please align yourself with my setup on https://www.wiki11.com . 请使自己符合我在https://www.wiki11.com上的设置。

Your issue is coming because nginx is trying to search for index.html file into /home/deploy/apps/mll/current/public which is not present there. 您的问题来了,因为nginx试图将index.html文件搜索到/home/deploy/apps/mll/current/public ,该文件在那里不存在。 In order to fix, you will need to add passenger with your nginx. 为了解决这个问题,您需要在nginx中添加乘客。

Instructions to follow. 遵循指示。

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 561F9B9CAC40B2F7
sudo apt-get install -y apt-transport-https ca-certificates

Add Passenger APT repository 添加旅客APT存储库

sudo sh -c 'echo deb https://oss-binaries.phusionpassenger.com/apt/passenger xenial main > /etc/apt/sources.list.d/passenger.list'
sudo apt-get update

Install passenger and nginx 安装passenger和nginx

sudo apt-get install -y nginx-extras passenger

Now start nginx webserver. 现在启动nginx Web服务器。

sudo service nginx start

Next, we need to update the Nginx configuration to point Passenger to the version of Ruby that we're using. 接下来,我们需要更新Nginx配置,以将Passenger指向我们正在使用的Ruby版本。

sudo vim /etc/nginx/nginx.conf

And add or uncomment 并添加或取消注释

include /etc/nginx/passenger.conf;

Save and close nginx.conf. 保存并关闭nginx.conf。 Then open /etc/nginx/passenger.conf 然后打开/etc/nginx/passenger.conf

sudo vim /etc/nginx/passenger.conf

If you are using .rbenv, then 如果您正在使用.rbenv,则

passenger_ruby /home/deploy/.rbenv/shims/ruby;

Or if you are using rvm, then 或者,如果您使用的是rvm,则

passenger_ruby /home/deploy/.rvm/wrappers/ruby-2.5.0/ruby;

Or if you are using system ruby, then 或者,如果您使用系统红宝石,则

passenger_ruby /usr/bin/ruby;

Next, restart nginx server 接下来,重启nginx服务器

sudo service nginx restart

Add passenger_enabled on; passenger_enabled on; into your site-enabled/centers or site-enabled/nodeapp file. 到启用了站点的/中心或启用站点/ nodeapp的文件中。

server {
        listen 80;
        listen [::]:80;

        root /home/deploy/apps/mll/current/public;
        index index.html index.htm;

        server_name myrailssite.com;
        passenger_enabled on;

        location / {
                try_files $uri $uri/ =404;
        }
}

Restart nginx server again, sudo service nginx restart . 再次重新启动nginx服务器, sudo service nginx restart Hopefully it should work. 希望它应该工作。

For more details, follow, https://www.phusionpassenger.com/library/install/nginx/install/oss/xenial/ 有关更多详细信息, 请访问https://www.phusionpassenger.com/library/install/nginx/install/oss/xenial/

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

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