簡體   English   中英

nginx錯誤/ home / deploy / myapp / current / public /“被禁止

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

我嘗試了一個類似問題的解決方案以及其他許多關於stackoverflow的解決方案,但是似乎都沒有一個解決方案。 即使配置了/etc/nginx/passenger.conf/etc/nginx/passenger.conf ,默認的niginx“歡迎”頁面仍在運行。 在我配置了/ etc / nginx / sites-enabled / default之后 ,通過更改我的rails應用程序的默認路徑,我開始收到403禁止錯誤。

這是錯誤日志。

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"

我的nginx文件如下。

/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

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的/啟用的站點- /默認

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;
        }
}

權限是:

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

請可以告訴別人我在做什么錯或我沒有做什么嗎? 謝謝

跟着這些步驟:

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

nginxuser :運行nginx的用戶,可能是以下之一: nginxwww-dataroot

不知道你到底錯過了什么。 請使自己符合我在https://www.wiki11.com上的設置。

您的問題來了,因為nginx試圖將index.html文件搜索到/home/deploy/apps/mll/current/public ,該文件在那里不存在。 為了解決這個問題,您需要在nginx中添加乘客。

遵循指示。

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

添加旅客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

安裝passenger和nginx

sudo apt-get install -y nginx-extras passenger

現在啟動nginx Web服務器。

sudo service nginx start

接下來,我們需要更新Nginx配置,以將Passenger指向我們正在使用的Ruby版本。

sudo vim /etc/nginx/nginx.conf

並添加或取消注釋

include /etc/nginx/passenger.conf;

保存並關閉nginx.conf。 然后打開/etc/nginx/passenger.conf

sudo vim /etc/nginx/passenger.conf

如果您正在使用.rbenv,則

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

或者,如果您使用的是rvm,則

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

或者,如果您使用系統紅寶石,則

passenger_ruby /usr/bin/ruby;

接下來,重啟nginx服務器

sudo service nginx restart

passenger_enabled on; 到啟用了站點的/中心或啟用站點/ 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;
        }
}

再次重新啟動nginx服務器, sudo service nginx restart 希望它應該工作。

有關更多詳細信息, 請訪問https://www.phusionpassenger.com/library/install/nginx/install/oss/xenial/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM