サービスlighttpdが再起動されます。

サービスlighttpdが再起動されます。

Ubuntuでlighttpdサービスを開始しています。私の考えは、CGIを介してPythonスクリプトを提供することです。しかし、これを行うと、403 Forbiddenが表示されますか?デバッグ方法とここで欠けている部分を助けてください。

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

ログにはまだ私のPythonバイナリではなくphp、htmlファイルを探していることがわかりますか?

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プロセスを使用して、要求がどのシステムコールに失敗したかを確認することもできます。

おすすめ記事