Python 无法解决烧瓶设置中的mod_wsgi异常
我想使用Python 3部署一个Flask应用程序。我正在运行Ubuntu 16.04,Apache2 我运行sudo apt get install libapache2-mod-wsgi-py3来安装wsgi 我按照指示去做。我的Linode服务器上有一个Flask应用程序,位于/var/www/html/hxueh.net/finance。财务文件夹中有一个文件和一个文件夹。结构是这样的Python 无法解决烧瓶设置中的mod_wsgi异常,python,apache,flask,mod-wsgi,Python,Apache,Flask,Mod Wsgi,我想使用Python 3部署一个Flask应用程序。我正在运行Ubuntu 16.04,Apache2 我运行sudo apt get install libapache2-mod-wsgi-py3来安装wsgi 我按照指示去做。我的Linode服务器上有一个Flask应用程序,位于/var/www/html/hxueh.net/finance。财务文件夹中有一个文件和一个文件夹。结构是这样的 |--------finance |----------------finance |--------
|--------finance
|----------------finance
|-----------------------static
|-----------------------templates
|-----------------------venv
|-----------------------application.py
|----------------finance.wsgi
在venv/bin中:
activate activate_this.py flask pip3.5 python3.5
activate.csh easy_install pip python python-config
activate.fish easy_install-3.5 pip3 python3 wheel
finance.wsgi是:
#!/usr/bin/python3
import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/var/www/html/hxueh.net/finance/")
from finance import app as application
#!/usr/bin/python3
import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/var/www/html/hxueh.net/Finance/")
from application import app as application
我的Apache2配置是:
<VirtualHost *:80>
ServerName finance.hxueh.net
ServerAdmin hxueh1996@gmail.com
WSGIScriptAlias / /var/www/html/hxueh.net/finance/finance.wsgi
<Directory /var/www/html/hxueh.net/finance/finance/>
Order allow,deny
Allow from all
</Directory>
<Directory /var/www/html/hxueh.net/finance>
WSGIProcessGroup finance
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
Alias /static /var/www/html/hxueh.net/finance/finance/static
<Directory /var/www/html/hxueh.net/finance/finance/static/>
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
更新:问题已解决。 我重写了结构并将wsgi文件放在项目中
|--------Finance
|----------------static
|----------------templates
|----------------venv
|----------------application.py
|----------------finance.wsgi
我还重写了Apache2文件。我禁用了WSGIProcessGroup,因为我不需要它
<VirtualHost *:80>
ServerName finance.hxueh.net
ServerAdmin hxueh1996@gmail.com
WSGIScriptAlias / /var/www/html/hxueh.net/Finance/finance.wsgi
<Directory /var/www/html/hxueh.net/Finance/>
Order allow,deny
Allow from all
</Directory>
<Directory /var/www/html/hxueh.net/Finance>
Order deny,allow
Allow from all
</Directory>
Alias /static /var/www/html/hxueh.net/Finance/static
<Directory /var/www/html/hxueh.net/Finance/static/>
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
最后,感谢Graham Dumpleton帮助我部署我的第一个web应用程序 您有:
WSGIProcessGroup finance
告诉mod_wsgi向运行在守护进程组中但尚未配置守护进程组的wsgi应用程序发送请求
在WSGIScriptAlias
指令之前添加:
WSGIDaemonProcess finance
另见:
pip
install方法从源代码中自行安装。见:
mod_wsgi-express module config
来获取需要添加到Apache配置中的配置,以便加载mod_wsgi?我确实运行了mod_wsgi-express安装模块
。我将WSGIPythonHome”/usr“
放在WSGIDaemonProcess和WSGIScriptAlias之前。它仍然不起作用。WSGIPythonHome
不能在VirtualHost
中,如果该值为/usr
,则实际上不需要,因为这是系统Python位置,因此应该自动找到。你把LoadModule
一行放在哪里了?我把它放在文件LoadModule wsgi_module”/usr/local/lib/python3.5/dist packages/mod_wsgi/server/mod_wsgi-py35.cpython-35m-x86_64-linux-gnu.so”的最上面。它仍然不起作用。没有必要使用pythonhome吗?当我运行python
时,它会运行python2,但我的项目是基于python3的。这需要一些调整吗?
WSGIDaemonProcess finance