正常に動作する CGIHTTPServer を作成しました。何をしても問題はありません。Python ページはレンダリングされず、ソース コードは常にブラウザに表示されます。
pyhttpd.py
#!/usr/bin/python
import CGIHTTPServer
import BaseHTTPServer
class Handler(CGIHTTPServer.CGIHTTPRequestHandler):
cgi_directories = [""]
PORT = 8080
httpd = BaseHTTPServer.HTTPServer(("", PORT), Handler)
print "serving at port", PORT
httpd.serve_forever()
cgi-bin/hello.py
#!/usr/bin/python
print 'Content-Type: text/html'
print
print '<html>'
print '<head><title>Hello</title></head>'
print '<body>'
print '<h2>Hello World</h2>'
print '</body></html>'
http://some.ip.address:8080/cgi-bin/hello.py :
#!/usr/bin/python
print 'Content-Type: text/html'
print
print '<html>'
print '<head><title>Hello</title></head>'
print '<body>'
print '<h2>Hello World</h2>'
print '</body></html>'
すべてのファイルのアクセス許可を実行可能に設定しました。.html ファイルは正常にレンダリングされます。サーバーが実行されているルート フォルダーにファイルを戻しても違いはありません。ルートと別の通常のユーザーとして実行してみました。同じ結果。
「レンダリングされていないpythonページ」をグーグルで試してみましたが、有用なものは見つかりませんでした!
編集
また、オーバーライドなしでより単純なサーバーを実行しようとしましたが、結果は同じで、pything コードはレンダリングされません。
pyserv.py
#!/usr/bin/python
from BaseHTTPServer import HTTPServer
from CGIHTTPServer import CGIHTTPRequestHandler
serve = HTTPServer(("",80),CGIHTTPRequestHandler)
serve.serve_forever()