Apache中的mod_wsgi无法正确呈现html根目录

问题描述

我有以下python脚本可插入我的index.html,该脚本最终将被拆分为header.html,footer.html,然后python代码将构成主体。如何告诉python将站点目录设置为所有与html和html相关的文件的根目录,以便CSS和img文件夹能够正确呈现?

#!/usr/bin/env python

import os

def application(environ,start_response):
    status = '200 OK'
    localpath = os.path.dirname(__file__)
    index_file = 'index.html'
    index_path = os.path.join(localpath,"adminUI",index_file)
    with open(index_path,'rb') as index:
        output = index.read()
    #output = b'Hello World!\n'
    response_headers = [('Content-type','text/html'),('Content-Length',str(len(output)))]
    start_response(status,response_headers)
    return [output]

解决方法

没关系,将Alias添加到虚拟httpd.conf中可以解决此问题:

Alias /img /usr/local/apache2/site/img
Alias ../vendors /usr/local/apache2/vendors