在DigitalOcean的服务器上部署flaskblog应用
在DigitalOcean上部署了flaskblog,项目虽小,部署中也学到了很多东西。
操作系统选择的是Ubuntu14.04,原因就是平时自己主要使用这个版本,顺手而已,所以你自己可以根据需要选择合适的linux版本。
部署方案:
Virtualenv+Gunicorn+Nginx+Supervisor
从这里下载项目的代码flaskblog, 工程中带有简单的配置文件参考。
可以先访问flaskblog看一下。
注意
本文中使用Ubuntu14.04 64位主机, 创建一个名为xin的用户,进行部署。
本文重点部署,所有linux的相关操作不做详细介绍。
部署目录是(/home/xin/www/flaskblog),所以请注意配置文件中的目录。
环境
系统:Ubuntu 14.04 64
Web Server: Nginx
虚拟环境: Virtualenv
WSGI Server: Gunicorn
数据库: MySQL
Monitor: Supervisor
使用supervisor主要是监控gunicorn的运行,保证服务器的可以持续运行。
安装
安装软件
$ sudo apt-get install python-pip $ sudo apt-get install python-dev $ sudo pip install virtualenv $ sudo apt-get install mysql-server $ sudo apt-get install libmysqlclient-dev $ sudo apt-get install nginx $ sudo apt-get install supervisor
下载工程并开启虚拟环境
使用git下载代码到(/home/xin/www/flaskblog)
$ git clone https://github.com/defshine/flaskblog.git $ cd flaskblog
启动虚拟环境,安装工程依赖
$ virtualenv venv $ source venv/bin/activate (venv)$ pip install -r requirements.txt
如何退出虚拟环境
(venv)$ deactivate
数据库
在MySQL数据库中创建数据库(flaskblog),修改 config.py中的数据库的配置
初始化数据库并创建管理员用户
(venv)$ python manage.py create_db (venv)$ python manage.py create_user -u admin -p 123456
开启监控
根据自己的情况,编辑工程下的supervisor配置文件(flaskblog.conf),然后复制到系统目录中
$ sudo cp flaskblog.conf /etc/supervisor/conf.d/
重新载入配置文件,并启动flaskblog
$ sudo supervisorctl reload $ sudo supervisorctl start flaskblog
查看运行状态
$ sudo supervisorctl status
Nginx
修改nginx的配置文件(flaskblog),然后复制到系统目录中去,并创建软链接。重启nignx。
$ sudo cp flaskblog /etc/nginx/site-available/ $ cd /etc/nginx/site-enabled $ sudo ln -s /etc/nginx/site-avalaible/flaskblog . $ sudo service nginx reload $ sudo service nginx restart
查看nginx状态
$ sudo service nginx status
然后,就可以通过ip地址访问了。当然,配置好域名,访问起来更好。
flaskblog这个小项目,刚刚有个小雏形,后续还可以开发一些小特性。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Solution to permission issues when viewing Python version in Linux terminal When you try to view Python version in Linux terminal, enter python...

When using Python's pandas library, how to copy whole columns between two DataFrames with different structures is a common problem. Suppose we have two Dats...

How to teach computer novice programming basics within 10 hours? If you only have 10 hours to teach computer novice some programming knowledge, what would you choose to teach...

How to avoid being detected when using FiddlerEverywhere for man-in-the-middle readings When you use FiddlerEverywhere...

How does Uvicorn continuously listen for HTTP requests? Uvicorn is a lightweight web server based on ASGI. One of its core functions is to listen for HTTP requests and proceed...

The article discusses popular Python libraries like NumPy, Pandas, Matplotlib, Scikit-learn, TensorFlow, Django, Flask, and Requests, detailing their uses in scientific computing, data analysis, visualization, machine learning, web development, and H

In Python, how to dynamically create an object through a string and call its methods? This is a common programming requirement, especially if it needs to be configured or run...

Using python in Linux terminal...
