環境:
CentOS7.5 + Nginx1.16 + PHP7.2.17
已搭好一切,運行正常,phpinfo(); 輸出正常。
現準備新開一個網站,由于本機服務器的磁盤空間不足,便掛載同一局域網內的另一臺服務器的共享檔案夾,用于新網站的根目錄。
于是:mount -t nfs 10.x.x.xxx:/dev/db4/test /mnt/test # 這條命令是成功執行的。且在本機上是可以列出/mnt/test 目錄下的檔案,且具有讀寫權限。并設定為開機自動掛載,一切正常!!
那問題來了。。
在 NGINX 的 組態檔里將網站根目錄指向本機的 /mnt/test ,也就是同一局域網內的另一臺服務器的共享檔案夾,并在此目錄下有一個 index.php 的檔案,是phpinfo();的,無論修改什么,訪問網站都永遠是 403 錯誤,
curl 127.0.0.1 得到的不是phpinfo(); 而是得到如下:
[root@server ~]# curl 127.0.0.1
<html>
<head><title>403 Forbidden</title></head>
<body>
<center><h1>403 Forbidden</h1></center>
<hr><center>nginx/1.16.0</center>
</body>
</html>
然后,umount 后,在/mnt/test 下新建一個 index.php,是phpinfo(); 則可以顯示相應的 內容。。
請高手解答!!!
uj5u.com熱心網友回復:
nginx 默認禁止訪問目錄, 可以使用 autoindex on; 命令解除目錄訪問限制uj5u.com熱心網友回復:
謝謝解答~~我不是這個意思,,
是打算把網站的根目錄指向同一局域網內的另一個服務器的共享檔案夾。。
uj5u.com熱心網友回復:
貼一下 nginx的 error.log 吧uj5u.com熱心網友回復:
估計還是權限的問題, nginx worker的用戶是nginx或者nobody, 看看這個賬戶是不是有權限
# 編輯檔案 /etc/fstab ,添加如下一行,保存后重啟(id資訊可以通過終端中的id命令查看)
//10.1.1.100/home/ /media/smbfs cifs defaults,username=xxx,password=yyy,uid=uid,gid=gid 0 0 //有密碼的samba共享
//10.1.1.100/home/ /media/smbfs cifs defaults,guest 0 0 //無密碼的samba共享
uj5u.com熱心網友回復:
另外 mount -t nfs 10.x.x.xxx:/dev/db4/test /mnt/test 這條命令有問題吧/dev/db4 設備下哪里來的 test檔案夾 ?
uj5u.com熱心網友回復:
嗯,,對,,,,這個命令是為了不泄露我的資訊,特地修改為這樣的,實際的命令是可以正確執行的。。
具體就不寫了。。
貼上 error.log 相應的敏感資訊還是會隱藏一下的。。請諒解。。。
[root@server nginx]# cat /usr/local/nginx/error.log
2019/05/24 09:15:08 [notice] 5300#5300: signal process started
2019/05/24 09:37:36 [notice] 5354#5354: signal process started
2019/05/24 09:37:44 [error] 5358#5358: *1 "/mnt/test/index.php" is forbidden (13: Permission denied), client: 10.x.xxx.xx, server: localhost, request: "GET / HTTP/1.1", host: "10.x.x.xxx"
2019/05/24 09:37:47 [error] 5358#5358: *1 "/mnt/test/index.php" is forbidden (13: Permission denied), client: 10.x.xxx.xx, server: localhost, request: "GET / HTTP/1.1", host: "10.x.x.xxx"
2019/05/24 09:37:47 [error] 5358#5358: *1 "/mnt/test/index.php" is forbidden (13: Permission denied), client: 10.x.xxx.xx, server: localhost, request: "GET / HTTP/1.1", host: "10.x.x.xxx"
2019/05/24 09:37:47 [error] 5358#5358: *1 "/mnt/test/index.php" is forbidden (13: Permission denied), client: 10.x.xxx.xx, server: localhost, request: "GET / HTTP/1.1", host: "10.x.x.xxx"
2019/05/24 10:01:32 [error] 3866#3866: *1 "/mnt/test/index.php" is forbidden (13: Permission denied), client: 127.0.0.1, server: localhost, request: "GET / HTTP/1.1", host: "127.0.0.1"
2019/05/24 11:16:45 [error] 3866#3866: *2 "/mnt/test/index.php" is forbidden (13: Permission denied), client: 10.x.xxx.xx, server: localhost, request: "GET / HTTP/1.1", host: "10.x.x.xxx"
-----------------------------------------------
其中 10.x.x.xxx 和 10.x.xxx.xx 確定是網段可以互通的。。
uj5u.com熱心網友回復:
這個 cifs 的方式,我試過無法掛載另一臺Linux 服務器的 共享檔案夾。可能是我不會弄吧。。
不過,我安裝了相關軟體后,可以通過:smbclient -L 10.x.x.xxx -U user%pass 列出目標服務器的相應共享明細。。
uj5u.com熱心網友回復:
[error] 3866#3866: *1 "/mnt/test/index.php" is forbidden ???nginx 應該用 root /mnt/test; 命令之地web根目錄, 之后直接訪問 index.php, 怎么能訪問 /mnt/test/index.php ?
uj5u.com熱心網友回復:

就是這樣的呀。
uj5u.com熱心網友回復:

uj5u.com熱心網友回復:
權限問題。web服務器映射完以后,獲取的權限對應到nfs服務器應該是nobody用戶。改一下nfs服務器目錄的權限試試,或者在共享nfs的時候用(rw, no_root_squash)引數uj5u.com熱心網友回復:
這個不太懂,能詳細點嗎?都是百度一步步走到這的。。
你說得情況就不會怎么搞了。。
uj5u.com熱心網友回復:
web服務器掛載了nfs,此時你的php使用nobody身份訪問nfs服務器的資源,但是權限不夠,所以失敗。在nfs服務器10.x.x.xxx上,修改一下exports引數,/dev/db4/test *(rw,sync,no_subtree_check,no_root_squash)
測驗一下如果還不行,給/dev/db4/test設定成777看看有沒有效果。
uj5u.com熱心網友回復:
嗯。好的,不過我到現在已經確定是權限問題了。。因為現在我不知道搞了什么,反正多是百度的方法。現在是可以正常顯示了。。
好的,我在試試到底是哪里的問題。。
謝謝~~
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/125920.html
標籤:專題技術討論區
