使用flask开发一个应用,需要部署,可是按照网络上的一些blog总是会报各种错误,实在配置不好了,烦请大叫指教。
使用的是阿里云服务器,Ubuntu 12.04.4 LTS。
大致步骤是模仿开源中国步骤完成的,如果完全按照原来的步骤进行是可以访问的,但是如果更改成我只得代码就会报
502 Bad Gateway
我的代码是存放在Github
-----下面是我修改之后的配置文件。
1. 创建/var/www/flask-blog-test/flask-blog-test.conf
server {
listen 80;
server_name localhost;
charset utf-8;
client_max_body_size 75M;
location /static {
root /var/www/flask-blog-test/;
}
location / { try_files $uri @yourapplication; }
location @yourapplication {
include uwsgi_params;
uwsgi_pass unix:/var/www/flask-blog-test/flask-blog-test.sock;
}
}
ln -s /var/www/flask-blog-test/flask-blog-test.conf /etc/nginx/conf.d/
/etc/init.d/nginx restart
- 创建/var/www/flask-blog-test/flask-blog-test-uwsgi.ini
[uwsgi]
#application's base folder
base = /var/www/flask-blog-test
#python module to import
app = app
module = %(app)
home = %(base)/venv
pythonpath = %(base)
#socket file's location
socket = /var/www/flask-blog-test/%n.sock
#permissions for the socket file
chmod-socket = 666
#the variable that holds a flask application inside the module imported at line #6
callable = app
#location of log files
logto = /var/log/uwsgi/%n.log
```
sudo mkdir -p /var/log/uwsgi
3. 启动uwsgi
uwsgi --ini /var/www/flask-blog-test/flask-blog-test-uwsgi.ini
4. 文件目录是
flask-blog-test
│
│──── venv
│ │──── bin
│ │────include
│ │──── lib
│ │──── local
│────app.py
│
│────static
│────templates
│────flask-blog-test-uwsgi.ini
│────flask-blog-test.conf
nginx+uwsgi+python+flask给你一个参考吧
1.修改
/etc/nginx/nginx.conf
文件默认配置基础上改了
Virtual Host Configs
:2.创建
/etc/nginx/sites-enabled/www.xxx.com.conf
文件3.创建
/etc/uwsgi/apps-enabled/www.xxx.com.ini
文件用了virtualenv:
这是代码部署的目录:
4.代码的结构
代码的目录是这样的:
代码目录里有一个
runserver.py
:其中
app
是Flask
对象5.修改权限
6.记得安装
uwsgi-plugin-python