[英]Running Python 3 Script on Apache 2.4 Web Server
I have Apache 2.4 installed and running on localhost. 我安装了Apache 2.4,并在localhost上运行。 I am trying to get CGI to work through editing httpd.conf so it will be able to run my python scripts. 我试图通过编辑httpd.conf来使CGI正常工作,以便它能够运行我的python脚本。
All I want it to do currently is be able to print "Hello World" so I know it is working. 我现在所希望做的就是能够打印“ Hello World”,所以我知道它正在工作。
print("hello world")
This is a copy of my httpd.conf file as of submitting this post. 这是提交此帖子时我的httpd.conf文件的副本。
Define SRVROOT "/apache24ah64"
ServerRoot "${SRVROOT}"
LoadModule access_compat_module modules/mod_access_compat.so
LoadModule actions_module modules/mod_actions.so
LoadModule alias_module modules/mod_alias.so
LoadModule allowmethods_module modules/mod_allowmethods.so
LoadModule asis_module modules/mod_asis.so
LoadModule auth_basic_module modules/mod_auth_basic.so
LoadModule authn_core_module modules/mod_authn_core.so
LoadModule authn_file_module modules/mod_authn_file.so
LoadModule authz_core_module modules/mod_authz_core.so
LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
LoadModule authz_host_module modules/mod_authz_host.so
LoadModule authz_user_module modules/mod_authz_user.so
LoadModule autoindex_module modules/mod_autoindex.so
LoadModule cgi_module modules/mod_cgi.so
LoadModule dir_module modules/mod_dir.so
LoadModule env_module modules/mod_env.so
LoadModule include_module modules/mod_include.so
LoadModule isapi_module modules/mod_isapi.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule mime_module modules/mod_mime.so
LoadModule negotiation_module modules/mod_negotiation.so
LoadModule setenvif_module modules/mod_setenvif.so
<IfModule unixd_module>
User daemon
Group daemon
</IfModule>
ServerAdmin admin@example.com
<Directory C:\Apache24\htdocs>
Options +ExecCGI
AddHandler cgi-script .cgi py
</Directory>
DocumentRoot "${SRVROOT}/htdocs"
<Directory "${SRVROOT}/htdocs">
Options Indexes FollowSymLinks FollowSymLinks ExecCGI
AllowOverride None
Require all granted
</Directory>
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
<Files ".ht*">
Require all denied
</Files>
ErrorLog "logs/error.log"
LogLevel warn
<IfModule log_config_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
<IfModule logio_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
</IfModule>
CustomLog "logs/access.log" common
</IfModule>
<IfModule alias_module>
ScriptAlias /cgi-bin/ "${SRVROOT}/cgi-bin/"
</IfModule>
<IfModule cgid_module>
</IfModule>
<Directory "${SRVROOT}/cgi-bin">
AllowOverride None
Options None
Require all granted
</Directory>
<IfModule headers_module>
RequestHeader unset Proxy early
</IfModule>
<IfModule mime_module>
TypesConfig conf/mime.types
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddHandler cgi-script .cgi .py
</IfModule>
<IfModule proxy_html_module>
Include conf/extra/proxy-html.conf
</IfModule>
<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>
I have looked through the documentation and at a couple of different tutorials but I haven't been able to find what is wrong. 我浏览了文档并浏览了一些不同的教程,但是我一直找不到错误的地方。
The python script is inside C:\\Apache24\\htdocs Python Version 3.7 Apache 2.4 python脚本位于C:\\ Apache24 \\ htdocs Python版本3.7 Apache 2.4中
Changes to the httpd.conf file: 对httpd.conf文件的更改:
Options Indexes FollowSymLinks ExecCGI 选项索引FollowSymLinks ExecCGI
AddHandler cgi-script .cgi .py AddHandler cgi-script .cgi .py
LoadModule cgid_module modules/mod_cgid.so LoadModule cgid_module modules / mod_cgid.so
I have a python script running as index.py
like that: 我有一个像index.py
这样运行的python脚本:
DirectoryIndex index.py
<Directory "/var/www/xyz">
Options +ExecCGI
AddHandler cgi-script .py
</Directory>
I think you have the correct arguments, but they need to be in the <Directory>
section. 我认为您具有正确的参数,但是它们必须位于<Directory>
部分中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.