Home Backend Development Python Tutorial 在DigitalOcean的服务器上部署flaskblog应用

在DigitalOcean的服务器上部署flaskblog应用

Jun 10, 2016 pm 03:07 PM

在DigitalOcean上部署了flaskblog,项目虽小,部署中也学到了很多东西。
操作系统选择的是Ubuntu14.04,原因就是平时自己主要使用这个版本,顺手而已,所以你自己可以根据需要选择合适的linux版本。
部署方案:

Virtualenv+Gunicorn+Nginx+Supervisor
Copy after login

从这里下载项目的代码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 
Copy after login


下载工程并开启虚拟环境

使用git下载代码到(/home/xin/www/flaskblog)

$ git clone https://github.com/defshine/flaskblog.git 
$ cd flaskblog   
Copy after login


启动虚拟环境,安装工程依赖

$ virtualenv venv  
$ source venv/bin/activate  
(venv)$ pip install -r requirements.txt  
Copy after login

如何退出虚拟环境

(venv)$ deactivate 
Copy after login

数据库

在MySQL数据库中创建数据库(flaskblog),修改 config.py中的数据库的配置
初始化数据库并创建管理员用户

(venv)$ python manage.py create_db 
(venv)$ python manage.py create_user -u admin -p 123456 
Copy after login

开启监控

根据自己的情况,编辑工程下的supervisor配置文件(flaskblog.conf),然后复制到系统目录中

$ sudo cp flaskblog.conf /etc/supervisor/conf.d/ 
Copy after login

重新载入配置文件,并启动flaskblog

$ sudo supervisorctl reload 
$ sudo supervisorctl start flaskblog 
Copy after login

查看运行状态

$ sudo supervisorctl status 
Copy after login

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 
Copy after login

查看nginx状态

$ sudo service nginx status 
Copy after login

然后,就可以通过ip地址访问了。当然,配置好域名,访问起来更好。
flaskblog这个小项目,刚刚有个小雏形,后续还可以开发一些小特性。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to solve the permissions problem encountered when viewing Python version in Linux terminal? How to solve the permissions problem encountered when viewing Python version in Linux terminal? Apr 01, 2025 pm 05:09 PM

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

How to efficiently copy the entire column of one DataFrame into another DataFrame with different structures in Python? How to efficiently copy the entire column of one DataFrame into another DataFrame with different structures in Python? Apr 01, 2025 pm 11:15 PM

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 in project and problem-driven methods within 10 hours? How to teach computer novice programming basics in project and problem-driven methods within 10 hours? Apr 02, 2025 am 07:18 AM

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 by the browser when using Fiddler Everywhere for man-in-the-middle reading? How to avoid being detected by the browser when using Fiddler Everywhere for man-in-the-middle reading? Apr 02, 2025 am 07:15 AM

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 without serving_forever()? How does Uvicorn continuously listen for HTTP requests without serving_forever()? Apr 01, 2025 pm 10:51 PM

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...

What are some popular Python libraries and their uses? What are some popular Python libraries and their uses? Mar 21, 2025 pm 06:46 PM

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

How to dynamically create an object through a string and call its methods in Python? How to dynamically create an object through a string and call its methods in Python? Apr 01, 2025 pm 11:18 PM

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...

How to solve permission issues when using python --version command in Linux terminal? How to solve permission issues when using python --version command in Linux terminal? Apr 02, 2025 am 06:36 AM

Using python in Linux terminal...

See all articles