简体   繁体   English

Python WSGI处理程序直接在Apache .htaccess中,而不在VirtualHost中

[英]Python WSGI handler directly in Apache .htaccess, not in VirtualHost

I know how to have a Python Bottle server: 我知道如何拥有一个Python Bottle服务器:

import os
from bottle import route, template, default_app
os.chdir(os.path.dirname(__file__))

@route('/hello')
def hello():
    return template('Hello world')

application = default_app()

run with WSGI, configured like this with Apache: 使用WSGI运行,并使用Apache这样配置:

<VirtualHost *:80>
  ServerName example.com
  <Directory />
    AllowOverride All
    Require all granted
  </Directory>
  WSGIScriptAlias / /var/www/wsgi_test/app.wsgi
</VirtualHost>

Is it possible to do the WSGI configuration directly in the .htaccess ? 是否可以直接在.htaccess进行WSGI配置

I just found the doc , and it seems that the answer is no, sadly: 我刚刚找到了doc ,可悲的是,答案似乎是否定的:

When using mod_cgi to host CGI applications, this would be done using the ScriptAlias directive. 使用mod_cgi托管CGI应用程序时,可以使用ScriptAlias指令来完成。 For mod_wsgi, the directive is instead called WSGIScriptAlias: 对于mod_wsgi,该指令改名为WSGIScriptAlias:

 WSGIScriptAlias /myapp /usr/local/www/wsgi-scripts/myapp.wsgi 

This directive can only appear in the main Apache configuration files. 该指令只能出现在主要的Apache配置文件中。 The directive can be used at server scope but would normally be placed within the VirtualHost container for a particular site. 该指令可以在服务器范围内使用,但通常会放置在特定站点的VirtualHost容器中。 It cannot be used within either of the Location, Directory or Files container directives, nor can it be used within a “.htaccess” file. 不能在Location,Directory或Files容器指令中使用它也不能在“ .htaccess”文件中使用它。

(emphasis mine) (强调我的)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM