Apache服务器上的Python应用程序

时间:2019-05-20 14:32:28

标签: python apache mod-wsgi httpd.conf

我正在尝试在Apache HTTPD服务器上托管Python应用程序,但最近2周一直在苦苦挣扎。我必须遵循Stackoverflow上Google和此处的所有说明,但无法解决该问题。我面临访问被拒绝的问题。

[cgi:error][pid 402] [client xx.xx.xx.xx:64064] AH01215:
(13)Permission denied: exec of '/var/www/html/RWorkflow/main.py failed

[cgi:error][pid 402] [client xx.xx.xx.xx:64064] End of script output before headers: main.py

我正在尽力按照此处提供的说明进行操作,但是没有用。如果我在这里所有解决方案中都找不到任何东西,请原谅,但是有关我的情况的任何专家建议都将为您提供很大的帮助。

请在下面找到我的详细信息。

服务器详细信息

Server version: Apache/2.4.6 (Red Hat Enterprise Linux)
Architecture:   64-bit
Server MPM:     prefork
threaded:     no
forked:     yes (variable process count)

政策和MOD_WSGI

[pid 401] SELinux policy enabled; httpd running as context system_u:system_r:httpd_t:s0
[pid 401] AH01232: suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[pid 401] AH00163: Apache/2.4.6 (Red Hat Enterprise Linux) mod_wsgi/3.4 Python/2.7.5 configured -- resuming normal operations

我的HTTPD.conf文件

ServerRoot "/etc/httpd"

Listen 80

Include conf.modules.d/*.conf

User apache
Group apache

ServerAdmin root@localhost

<Directory />
    AllowOverride none
    Require all denied
</Directory>


DocumentRoot "/var/www/html"

<Directory "/var/www">
    AllowOverride None
    # Allow open access:
    Require all granted
</Directory>

<Directory "/var/www/html">

    AddHandler cgi-script .cgi .py
    Options Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews Indexes
    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>
      # You need to enable mod_logio.c to use %I and %O
      LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
    </IfModule>

    CustomLog "logs/access_log" combined
</IfModule>

<IfModule alias_module>

    ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"

</IfModule>

<Directory "/var/www/cgi-bin">
    AllowOverride None
    Options None
    Require all granted
</Directory>

<IfModule mime_module>
    TypesConfig /etc/mime.types

    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz

    AddType text/html .shtml
    AddOutputFilter INCLUDES .shtml
</IfModule>


AddDefaultCharset UTF-8

<IfModule mime_magic_module>
    MIMEMagicFile conf/magic
</IfModule>

EnableSendfile on
IncludeOptional conf.d/*.conf
/etc/httpd/conf.d / 中的

Rworkflow.conf文件

<VirtualHost *:80>
     # Add machine's IP address (use ifconfig command)
     ServerName myserveraddress
     # Give an alias to to start your website url with
     WSGIScriptAlias /rworkflow /var/www/html/RWorkflow/main.py

     <Directory /var/www/html/RWorkflow/>
        # set permissions as per apache2.conf file
        Options FollowSymLinks
        Options +ExecCGI

        AddHandler cgi-script .py
        AllowOverride None
        Require all granted
    </Directory>
</VirtualHost>

main.py

    #!/opt/anaconda3/python3.6/bin/python3.6
    print ("Content-type: text/html")
    print ("")
    print ("<html><head>")
    print ("")
    print ("</head><body>")
    print ("Hello.")
    print ("</body></html>")

为此main.py所有者是apache并将权限设置为755 权利:rwxr-xr-x

我不确定是否在此提供了所有详细信息,但是如果您需要更多详细信息,请告诉我。

我知道这里有很多解决方案,但我无法遵循,因此请再次发布我的问题。

请帮助。

0 个答案:

没有答案