帶有 Shell 腳本的 CGI

帶有 Shell 腳本的 CGI

我在使用 Shell 腳本運行 CGI 範例時遇到問題,無法存取在「/tmp/shell」之後的範例中建立的目錄。透過訪問地址“http://localhost/shell”應該會看到“Index of shel”頁面,但會出現 403 錯誤,並顯示訊息“您無權訪問此伺服器上的/shell/。

我使用的是Fedora 24,我認為apache用戶名為“Apache”,好吧,至少在文件“passwd”中有一個apache用戶,我想運行CGI文件的資料夾的權限為777並且已更改用戶使用chown到“apache”,但仍然給出403 錯誤。

我的檔案「/etc/httpd/conf/httpd.conf」如下所示:

$ Tail -n20 /etc/httpd/conf/httpd.conf

# Settings for the study of Shell Script and CGI

Alias ​​/shell "/tmp/shell/"

<Directory "/tmp/shell/">
    Options Indexes FollowSymlinks ExecCGI
    AllowOverride None
    Order allow, deny
    Allow from all
</ Directory>

我的/tmp/shell:

$ ls -ld /tmp/ /tmp/shell
drwxrwxrwt. 15 root   root   480 Out  1 13:53 /tmp/
drwxrwxr-x.  2 apache apache  40 Out  1 13:52 /tmp/shell

Apache 正常運作在http://localhost,我不明白為什麼我無法存取/tmp/shell。我在這裡要瘋了!

有人能幫我嗎?

答案1

/tmpFedora 24 使用 systemd,並且可能只是為 httpd 進程設定一個私有的。您可以使用以下命令檢查這一點

sudo systemctl show -p PrivateTmp httpd

您可以透過建立一個/etc/systemd/system/httpd.service包含以下內容的檔案來覆蓋它

.include /lib/systemd/system/httpd.service
[Service]
PrivateTmp=false

sudo systemctl daemon-reload在重新啟動服務之前執行此操作。

相關內容