2015-11-02 56 views
2

禁止nginx的我已經閱讀beginner's guide of nginx403在Ubuntu

server { 
    location/{ 
     root /data/www; 
    } 

    location /images/ { 
     root /data; 
    } 
} 

http://localhost/images/example.png - > /data/images/example.png

http://localhost/some/example.html - > /data/www/some/example.html

所以我的nginx的配置:

server { 
      listen 443; 
      server_name localhost; 
      ssl on; 
      ssl_certificate /home/attolee/sslkey/example.crt; 
      ssl_certificate_key /home/attolee/sslkey/example.key; 
      ssl_session_timeout 5m; 
      ssl_protocols TLSv1 TLSv1.1 TLSv1.2; 
      ssl_ciphers ALL:!ADH:!EXPORT56:-RC4+RSA:+HIGH:+MEDIUM:!EXP; 
      ssl_prefer_server_ciphers on; 

      location/{ 
        root /home/attolee; 
        index index.html; 
      } 

      location /hi/ { 
        root /home/attolee; 
        index hi.html; 
      } 
    } 

我想

  1. https://host/訪問/home/attolee/index.html,
  2. https://host/hi/訪問/home/attolee/hi/hi.html,

現在1個工作,2失敗,403禁止。

錯誤日誌告訴我是13: Permission denied

因此,我檢查自己和/ home/attolee和/ home/attolee/hi /以及hi.html組。

drwxr-xr-x 6 attolee attolee 4096 Nov 2 17:08 attolee/ 
drw-rw-rw- 2 root root 4096 Nov 2 17:12 hi/ 
-rw-rw-rw- 1 root root  24 Nov 2 17:12 hi.html 

然後檢查nginx進程使用htop的USER屬性是root。

如何解決這個問題?

+0

目錄需要'x'權限 –

+0

@AlexeyTen用''x''更改''other''權限,它可以工作。 – attolee

回答

0

首先,在你的榜樣,你應該這樣做:

root /home/attolee; 
index index.html hi.html 
location/{ 
     try_files $uri $uri/ =404; 
} 

二,你並不需要以root運行nginx的。例如,在nginx.conf中,可以將其更改爲www-data。您必須在/ home/attolee /中移動/ home/hi,並使用正確的所有者設置/ home/attolee。