Ubuntu server 18.04.3 LTS
Apache/2.4.29 (Ubuntu)
which python3 => /usr/bin/python3
python3 -V => Python 3.6.9
installは、apt tasksel > lamp serverでインストール。
http://www.w3big.com/ja/python3/python3-cgi-programming.html
上記サイトの通りにしているのですが、pythonファイルが実行されません。
hello.pyを保存しますか、開きますかと聞かれます。
ブラウザでcontent-typeを確認するとtext/x-pythonとなっています。
/etc/mime.typesの
text/x-python .py
を、
text/html .py
とすると、content−typeは、text/htmlになるのですがうまく表示されるわけではありません。
どうすれば、上手く上のサイトのように実行されるでしょうか?
上手くcontent-typeがセット出来ていないとq&aに書かれていたのですが、、
EDIT1:
192.168.xxx.xxx/
にアクセスし、/var/www/html/index.html
が表示されるのは確認済み。
やったこと
1。/etc/apache2/apache2.confに、下の二行を追加。
ScriptAlias /cgi-bin/ /var/www/cgi-bin/
AddHandler cgi-script .cgi .pl .py
2。上二行を下のように少し変えて試す。
.cgi .pl .py => cgi pl py
3。下の六行を追加。
<Directory "/var/www/cgi-bin">
AllowOverride None
Options +ExecCGI
Order allow,deny
Allow from all
</Directory>
hello.pyのcontent~~~のところをいじる。
print("Content-Type: text/html")
print("content-type: txt/html")
print('Content-type: text/html')
print("Content_type: text/html")
print()をけして、print("Content-type: text/html\n")
4。chomd 755で実行可能にしました。
EDIT2:
apache2.confです。#から始まる部分は消しました。
DefaultRuntimeDir ${APACHE_RUN_DIR} PidFile ${APACHE_PID_FILE} Timeout 300 KeepAlive On MaxKeepAliveRequests 100 KeepAliveTimeout 5 User ${APACHE_RUN_USER} Group ${APACHE_RUN_GROUP} HostnameLookups Off ErrorLog ${APACHE_LOG_DIR}/error.log LogLevel warn IncludeOptional mods-enabled/*.load IncludeOptional mods-enabled/*.conf Include ports.conf <Directory /> Options FollowSymLinks AllowOverride None Require all denied </Directory> <Directory /usr/share> AllowOverride None Require all granted </Directory> <Directory /var/www/> Options Indexes FollowSymLinks AllowOverride None Require all granted </Directory> ScriptAlias /cgi-bin/ /var/www/cgi-bin/ AddHandler cgi-script .cgi .pl .py <Directory "/var/www/cgi-bin"> AllowOverride None Options +ExecCGI Require all granted </Directory> AccessFileName .htaccess <FilesMatch "^.ht"> Require all denied </FilesMatch> LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined LogFormat "%h %l %u %t \"%r\" %>s %O" common LogFormat "%{Referer}i -> %U" referer LogFormat "%{User-agent}i" agent IncludeOptional conf-enabled/*.conf IncludeOptional sites-enabled/*.conf
EDIT3:
azure virtual machinesで同じことをしてみました。
apt update
apt upgrade
apt install tasksel
ufw allow 80
apache2.conf は、上と同じ。
which python3 => /usr/bin/python3
python3 -V => Python 3.6.9
apachectl -v => Apache/2.4.26 (Ubuntu)
apatchectl configtest => Syntax OK
しかしうまくいきません。
回答1件
あなたの回答
tips
プレビュー