参考サイト
https://qiita.com/goodboy_max/items/833d482827bf0efab45a
上記サイトを見ながら構築しましたが
htmlページは見えるもののcgi-binフォルダーにあるcgitest.pyファイルは真白で何も表示されない状況で困っております。
どこが間違っているのかご教示いただけますと幸いです。
よろしくお願いいたします。
↓↓構築された環境↓↓
$ pwd /home/python $ ls -l total 16 drwxr-xr-x 1 root root 4096 Mar 15 07:53 cgi-bin -rwxr-xr-x 1 root root 84 Mar 15 01:36 cgiserver.py -rwxr-xr-x 1 root root 246 Mar 15 01:36 index.html $ cd cgi-bin $ ls -l total 4 -rwxr-xr-x 1 root root 350 Mar 15 07:51 cgitest.py $
Dockerfile
1FROM python:3.5.2 2MAINTAINER test test <test@gmail.com> 3 4RUN groupadd web 5RUN useradd -d /home/python -m python 6 7WORKDIR /home/python 8ADD cgiserver.py /home/python 9ADD index.html /home/python 10RUN mkdir cgi-bin 11ADD cgitest.py /home/python/cgi-bin 12RUN chmod 755 /home/python/cgi-bin/cgitest.py 13 14EXPOSE 8000 15ENTRYPOINT ["/usr/local/bin/python", "/home/python/cgiserver.py"] 16USER python
cgiserver.py
1import http.server 2http.server.test(HandlerClass=http.server.CGIHTTPRequestHandler)
cgitest.py
1#!/usr/local/bin/python 2# -*- coding: utf-8 -*- 3 4import cgi 5 6html_body = """ 7<!DOCTYPE html> 8<html> 9<head> 10<title>受信したデータを表示</title> 11<style> 12h1 { 13font-size: 3em; 14} 15</style> 16</head> 17<body> 18<h1>%s</h1> 19</body> 20</html> 21""" 22 23form = cgi.FieldStorage() 24text = form.getvalue('text','') 25 26print(html_body % (text))
index.html
1<!DOCTYPE html> 2<html> 3<head> 4<title>CGI Sample</title> 5</head> 6<body> 7<form action="/cgi-bin/cgitest.py" method="POST"> 8 <input type="text" name="text" value="test" /> 9 <input type="submit" name="submit" /> 10</form> 11</body> 12</html>
確認したURL
http://localhost:8000/
正常にWEBページが表示される
http://localhost:8000/cgi-bin/cgitest.py
真白で何も表示されない
http://localhost:8000/cgi-bin/cgitest1.py(存在しないURL)
404error
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2022/03/17 06:28 編集