[英]deploying flask-restful app using apache mod_wsgi
I'm trying to create a flask-restful based app, but not able to host it properly. 我正在尝试创建一个基于烧瓶的应用程序,但无法正确托管它。 Here is my virtual host file
FlaskApp.conf
: 这是我的虚拟主机文件
FlaskApp.conf
:
<VirtualHost *:80>
ServerName flaskapp
WSGIScriptAlias / /var/www/flaskapp/myopinion.wsgi
<Directory /var/www/flaskapp/flaskapp>
WSGIProcessGroup myopinion
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
and my wsgi file: 和我的wsgi文件:
#!/usr/bin/python
import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/var/www/flaskapp/")
from server import app as application
Server is my python module stored in /var/www/flaskapp/flaskapp
directory. 服务器是我的python模块,存储在
/var/www/flaskapp/flaskapp
目录中。
My virtual host file is located at /etc/apache2/sites_available/
and my .wsgi file is located in /var/www/flaskapp
directory. 我的虚拟主机文件位于
/etc/apache2/sites_available/
,我的.wsgi文件位于/var/www/flaskapp
目录中。
When I'm trying to access my urls from server.py
file it is giving error code 404 Not found: requested url /ques/ was not found on this server
. 当我尝试从
server.py
文件访问我的URL时,它给出错误代码404 Not found: requested url /ques/ was not found on this server
。
I'm in desperate need of help here, I'm stuck with this problem since past two weeks. 我在这里迫切需要帮助,从过去的两个星期以来,我一直在解决这个问题。 Please help me out here.
请帮帮我。
You might have a problem with your virtual host file. 您的虚拟主机文件可能有问题。 Try this:
尝试这个:
<VirtualHost *:80>
ServerName flaskapp
WSGIScriptAlias / /var/www/flaskapp/myopinion.wsgi
WSGIProcessGroup myopinion
<Directory /var/www/flaskapp/flaskapp/>
Order deny,allow
Allow from all
</Directory>
Your wsgi file is also not correct. 你的wsgi文件也不正确。 It should be:
它应该是:
#!/usr/bin/python
import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/var/www/flaskapp/")
from flaskapp import server as application
In the wsgi file, you put the directory name after from
, the object name after import
. 在wsgi文件中,将目录名放在
from
之后,将对象名放在import
之后。 Aliasing it as application
is not necessary, but a common practice. 将其别名为
application
不是必需的,而是常见的做法。
I used a similar apache-flask redirection for my flask application. 我在烧瓶应用程序中使用了类似的apache-flask重定向。 You can take a look at the tutorial which i followed.
你可以看看我遵循的教程。
Link : https://www.digitalocean.com/community/tutorials/how-to-deploy-a-flask-application-on-an-ubuntu-vps 链接: https : //www.digitalocean.com/community/tutorials/how-to-deploy-a-flask-application-on-an-ubuntu-vps
The mod_wsgi setup worked for me using the above link. 使用上面的链接,mod_wsgi设置对我有用。 I used it to redirect Flask port:5000 to Port 80 on apache2.
我用它将Flask端口:5000重定向到apache2上的端口80。 It is possible to install and enable mod_wsgi using the following commands in a shell:
可以在shell中使用以下命令安装和启用mod_wsgi:
sudo apt-get install libapache2-mod-wsgi python-dev
sudo a2enmod wsgi
Once the installation is done and everything is configured correctly, Apache has to be restarted using the following command: 一旦完成安装并正确配置了所有内容,则必须使用以下命令重新启动Apache:
sudo service apache2 restart
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.