【问题标题】:Apache alias site needs to load python script with wsgiApache 别名站点需要使用 wsgi 加载 python 脚本
【发布时间】:2017-09-19 10:55:21
【问题描述】:

我有一个使用这个 apache.conf 文件运行的站点:

<VirtualHost *:80>
    ServerAdmin krestensb@gmail.com
    ServerName skovstedconsulting.dk
    ServerAlias www.skovstedconsulting.dk
    DocumentRoot /var/www/skovstedconsulting/html

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    RewriteEngine on
    RewriteCond %{SERVER_NAME} =skovstedconsulting.dk [OR]
    RewriteCond %{SERVER_NAME} =www.skovstedconsulting.dk
    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

我想从子路径 /tdc 提供一个 python 脚本。所以我在 DocumentRoot 之后添加了这个:

    Alias /tdc /var/www/skovstedconsulting/html/tdc
    WSGIScriptAlias /tdc /var/www/skovstedconsulting/html/tdc/tdc.wsgi

tdc.wsgi 看起来像这样:

#!/usr/bin/python
import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/var/www/skovstedconsulting/html/tdc/")

from TDC import app as application
application.secret_key = 'Add your secret key'

我在访问 /tdc 时看到的只是目录的内容。

非常感谢任何帮助。

最好的问候克雷斯滕

【问题讨论】:

    标签: python apache mod-wsgi wsgi


    【解决方案1】:

    删除Alias /tdc /var/www/skovstedconsulting/html/tdc。你只想要WSGIScriptAliasAlias 将覆盖 WSGIScriptAlias

    见:

    您也不应该将 WSGI 脚本文件放在您现有的 DocumentRoot 下,因为人们可以下载您的源代码。

    【讨论】:

    • 它没有改变任何东西。
    • 注释掉任何重写规则以验证没有先行的事情。
    猜你喜欢
    • 2012-11-07
    • 1970-01-01
    • 1970-01-01
    • 2018-01-18
    • 2021-11-28
    • 2014-03-18
    • 2022-01-02
    • 2012-06-19
    • 2016-12-28
    相关资源
    最近更新 更多