我正在我的 ubuntu 中啟動 lighttpd 服務。但是,當我這樣做時,我會收到 403 禁止嗎?請幫助如何調試以及我在這裡缺少什麼?
vi /etc/lighttpd/lighttpd.conf
server.document-root "/home/httpd"
在lighttpd中啟用、CGI。
vi /etc/lighttpd/lighttpd.conf
server.modules = (
"mod_access",
"mod_alias",
"mod_compress",
"mod_redirect",
"mod_cgi",
"mod_rewrite",
)
為了讓 lighttpd 識別任何 python 腳本,我們需要在檔案末尾新增以下新部分。
$HTTP["url"] =~ "^/cgi-bin/" {
cgi.assign = (".py" => "/usr/bin/python")
}
為根資料夾授予適當的權限。
# chown www-data /home/httpd/cgi-bin
# chgrp www-data /home/httpd/cgi-bin
現在,寫 hello.py
vi /home/httpd/cgi-bin/hello.py
#! /usr/bin/python
#
print "Content-Type: text/html\n\n"
print '<html> <head> <meta-content="text/html; charset=UTF-8"/>'
print '<title> Raspberry Pi </title>
<p>
for count in range(1,100)
print'Hello World...'
print "/p> <body> </html>
Finally, restart the lighttpd service.
服務lighttpd重啟
But, when I try to access the page it says-
403 forbidden
這是我的資料夾,權限為/home/httpd。
/home/httpd$ ls -l
total 8
drwxr-xr-x 2 www-data www-data 4096 Apr 3 17:56 cgi-bin
drwxr-xr-x 2 www-data root 4096 Apr 3 16:41 html
這是 hello.py
/home/httpd/cgi-bin$ ls -l
total 4
-rwxrwxrwx 1 root www-data 244 Apr 3 17:56 hello.py
日誌說它仍在尋找 php、html 檔案而不是我的 python 二進位檔案?
read(7, "GET / HTTP/1.1\r\nHost: 10.0.2.15\r"..., 4159) = 328
stat("/home/httpd/", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
stat("/home/httpd/index.php", 0x7ffee411b9f0) = -1 ENOENT (No such file or directory)
stat("/home/httpd/index.html", 0x7ffee411b9f0) = -1 ENOENT (No such file or directory)
stat("/home/httpd/index.lighttpd.html", 0x7ffee411b9f0) = -1 ENOENT (No such file or directory)
setsockopt(7, SOL_TCP, TCP_CORK, [1], 4) = 0
writev(7, [{iov_base="HTTP/1.1 403 Forbidden\r\nContent-"..., iov_len=134}, {iov_base="<?xml version=\"1.0\" encoding=\"is"..., iov_len=345}], 2) = 479
setsockopt(7, SOL_TCP, TCP_CORK, [0], 4) = 0
ioctl(7, FIONREAD, [0]) = 0
read(7, 0x5606cf6ceaf0, 4159) = -1 EAGAIN (Resource temporarily unavailable)
epoll_ctl(6, EPOLL_CTL_ADD, 7, {EPOLLIN|EPOLLERR|EPOLLHUP, {u32=7, u64=7}}) = 0
accept4(4, 0x7ffee411bc10, [112], SOCK_CLOEXEC|SOCK_NONBLOCK) = -1 EAGAIN (Resource temporarily unavailable)
答案1
檢查lighttpd錯誤日誌,看看是否有任何痕跡。
檢查您的 SELinux 設置,並可能暫時停用強制執行以進行測試。
這是一個可能相關的較舊問題: https://serverfault.com/questions/335571/selinux-causes-permission-denied-when-starting-lighttpdfastcgi-via-upstart
如果您對更多細節感興趣,您也可以透過strace
lighttpd 進程來查看發出該請求時哪個系統呼叫失敗。