在CentOS 7.2 新增了nginx官方的yum來源,使用yum install nginx 安裝的nginx/1.10.2
安裝完成後我關閉了系統防火牆,預設站點可以正常訪問,我又添加了另一個虛擬主機設定文件,內容如下:
server {
listen 80;
server_name idas.it;
root /home/html;
index index.html index.php;
# location / {
# try_files $uri $uri/ /index.php?$query_string;
# }
location ~ \.php$ {
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
目錄權限如下:
[root@hrms /]# ll && cd /home && ll && cd html && ll
total 84
dr-xr-xr-x. 17 root root 4096 Nov 12 13:39 .
dr-xr-xr-x. 17 root root 4096 Nov 12 13:39 ..
lrwxrwxrwx. 1 root root 7 Nov 12 11:37 bin -> usr/bin
dr-xr-xr-x. 5 root root 4096 Nov 12 12:16 boot
drwxr-xr-x. 20 root root 3260 Nov 12 13:10 dev
drwxr-xr-x. 83 root root 8192 Nov 12 14:40 etc
drwxr-xr-x. 5 root root 78 Nov 12 15:27 home
lrwxrwxrwx. 1 root root 7 Nov 12 11:37 lib -> usr/lib
lrwxrwxrwx. 1 root root 9 Nov 12 11:37 lib64 -> usr/lib64
drwxr-xr-x. 2 root root 6 Aug 12 2015 media
drwxr-xr-x. 2 root root 6 Aug 12 2015 mnt
drwxr-xr-x. 2 root root 6 Aug 12 2015 opt
dr-xr-xr-x. 137 root root 0 Nov 12 13:10 proc
-rw-r--r--. 1 root root 43092 Nov 12 13:11 .readahead
dr-xr-x---. 6 root root 4096 Nov 12 15:23 root
drwxr-xr-x. 24 root root 680 Nov 12 15:31 run
lrwxrwxrwx. 1 root root 8 Nov 12 11:37 sbin -> usr/sbin
drwxr-xr-x. 2 root root 6 Aug 12 2015 srv
dr-xr-xr-x. 13 root root 0 Nov 12 13:10 sys
drwxrwxrwt. 10 root root 4096 Nov 12 15:31 tmp
drwxr-xr-x. 13 root root 4096 Nov 12 11:37 usr
drwxr-xr-x. 20 root root 4096 Nov 12 13:38 var
total 12
drwxr-xr-x. 5 root root 78 Nov 12 15:27 .
dr-xr-xr-x. 17 root root 4096 Nov 12 13:39 ..
-rw-r--r--. 1 root root 1097 Oct 19 00:35 default.conf
drwxrwxr-x. 2 root root 23 Nov 12 15:24 html
drwxr-xr-x. 5 mysql mysql 4096 Nov 12 14:22 mysql
drwxrwxr-x. 2 nginx nginx 6 Nov 12 14:41 php
total 4
drwxrwxr-x. 2 root root 23 Nov 12 15:24 .
drwxr-xr-x. 5 root root 78 Nov 12 15:27 ..
-rwxrwxr-x. 1 root root 612 Nov 12 15:24 index.html
權限都給了,但存取還是403 Forbidden,以下是nginx的錯誤日誌:
2016/11/12 15:31:28 [error] 17524#17524: *2 "/home/html/index.html" is forbidden (13: Permission denied), client: 10.120.9.254, server: idas.it, request: "GET / HTTP/1.1", host: "idas.it"
2016/11/12 15:39:28 [error] 17524#17524: *3 "/home/html/index.html" is forbidden (13: Permission denied), client: 10.120.9.254, server: idas.it, request: "GET / HTTP/1.1", host: "idas.it"
2016/11/12 15:39:29 [error] 17524#17524: *3 "/home/html/index.html" is forbidden (13: Permission denied), client: 10.120.9.254, server: idas.it, request: "GET / HTTP/1.1", host: "idas.it"
同樣的權限配置,為什麼在/var/share/nginx/html目錄就能正常訪問,而其他目錄都沒有權限呢?
[root@hrms html]# ps aux | grep nginx
nginx 17292 0.0 0.1 650776 10504 ? S 14:50 0:00 php-fpm: pool www
nginx 17293 0.0 0.1 650776 10500 ? S 14:50 0:00 php-fpm: pool www
nginx 17294 0.0 0.1 650776 10500 ? S 14:50 0:00 php-fpm: pool www
nginx 17295 0.0 0.1 650776 10500 ? S 14:50 0:00 php-fpm: pool www
nginx 17296 0.0 0.1 650776 10504 ? S 14:50 0:00 php-fpm: pool www
root 17523 0.0 0.0 47792 1164 ? Ss 15:31 0:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
nginx 17524 0.0 0.0 48184 2184 ? S 15:31 0:00 nginx: worker process
root 17617 0.0 0.0 112648 964 pts/0 S+ 16:19 0:00 grep --color=auto nginx
我後來把/home、子目錄及文件的所有者和和用戶組都設為nginx,但是依然是403 Forbidden,錯誤日誌還是一樣!
求老司機帶路! ! ! ! !
可以試試是否是SElinux沒關導致的,可以使用以下命令關閉:
好像跟什麼安全策略有關,透過軟連線應該可以解決,ln -s /var/nginx/html /home/html