Python 直接在 Apache .htaccess 中的 WSGI 处理程序,而不是在 VirtualHost 中
Python WSGI handler directly in Apache .htaccess, not in VirtualHost
我知道如何拥有 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()
运行 使用 WSGI,使用 Apache 配置如下:
<VirtualHost *:80>
ServerName example.com
<Directory />
AllowOverride All
Require all granted
</Directory>
WSGIScriptAlias / /var/www/wsgi_test/app.wsgi
</VirtualHost>
是否可以直接在.htaccess
中进行WSGI配置?
刚刚找到了doc,看来答案是否定的,遗憾:
When using mod_cgi to host CGI applications, this would be done using the ScriptAlias directive. For mod_wsgi, the directive is instead called WSGIScriptAlias:
WSGIScriptAlias /myapp /usr/local/www/wsgi-scripts/myapp.wsgi
This directive can only appear in the main Apache configuration files. The directive can be used at server scope but would normally be placed within the VirtualHost container for a particular site. It cannot be used within either of the Location, Directory or Files container directives, nor can it be used within a “.htaccess” file.
(强调我的)
我知道如何拥有 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()
运行 使用 WSGI,使用 Apache 配置如下:
<VirtualHost *:80>
ServerName example.com
<Directory />
AllowOverride All
Require all granted
</Directory>
WSGIScriptAlias / /var/www/wsgi_test/app.wsgi
</VirtualHost>
是否可以直接在.htaccess
中进行WSGI配置?
刚刚找到了doc,看来答案是否定的,遗憾:
When using mod_cgi to host CGI applications, this would be done using the ScriptAlias directive. For mod_wsgi, the directive is instead called WSGIScriptAlias:
WSGIScriptAlias /myapp /usr/local/www/wsgi-scripts/myapp.wsgi
This directive can only appear in the main Apache configuration files. The directive can be used at server scope but would normally be placed within the VirtualHost container for a particular site. It cannot be used within either of the Location, Directory or Files container directives, nor can it be used within a “.htaccess” file.
(强调我的)