服务lighttpd重启

服务lighttpd重启

我正在我的 ubuntu 中启动 lig​​httpd 服务。我的想法是通过 CGI 提供 python 脚本。但是,当我这样做时,我会收到 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&nbspWorld...'
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

如果您对更多细节感兴趣,您还可以通过stracelighttpd 进程来查看发出该请求时哪个系统调用失败。

相关内容