Centos+nginx+uwsgi+virtualenv+flask Multi-site environment construction

Source: Internet
Author: User
Tags virtual environment virtualenv

original link:http://localhost:8090/search/142294.html

Environment:

CentOS x64 6.6

Nginx 1.6.2

Python 2.7.9

Uwsgi 2.0.9

Virtualenv 12.0.5

Flask 0.10.1

Body:

1. Installing Nginx

Related Websites

1.1 Configuring Yum third-party feeds

The CentOS default source does not have an Nginx installation package, so let's modify the third-party source.

#cd ~ #wget http://www.atomicorp.com/installers/atomic#sh./atomic#yum check-update

1.2 Installing Nginx

#yum Install Nginx#service nginx start
#chkconfig Nginx on

2. Installation Class Library

#cd ~
#yum Groupinstall "Development tools" #yum install Zlib-devel bzip2-devel pcre-devel openssl-devel ncurses-devel Sqlite-devel Readline-devel Tk-devel

3. Install Python

Related websites:

Python

3.1 Installing the latest version

CentOS 6.6 is installed by default python2.6.6 version, we now install the latest version of python2.7.9

#cd ~ #wget Https://www.python.org/ftp/python/2.7.9/Python-2.7.9.tgz#tar xvf python-2.7.9.tgz#cd python-2.7.9.tgz#./ Configure--prefix=/usr/local#make && make Altinstall

3.2 Back up old version, link new version

Since the CentOS system's Yum program uses the python2.6.6 version of the previous system, in order to resolve version conflicts, we will first distinguish and relink the old and new versions of Python.

#mv/usr/bin/python/usr/bin/python2.6.6#ln-s/usr/local/bin/python2.7/usr/bin/python

3.3 Modifying the Yum configuration file

To reassign the Python program path that it uses:

#vi/usr/bin/yum

Find to:

#!/usr/bin/python

Modified to:

#!/usr/bin/python2.6.6

After the modifications are complete, use the "python" command to enter the python2.7.9 environment.

Exit the environment using the exit () command.

4. Install Python package management tool

Related websites:

Distribute

#cd ~ #wget Https://pypi.python.org/packages/source/d/distribute/distribute-0.6.49.tar.gz#tar XF DISTRIBUTE-0.6.49.TAR.GZ#CD Distribute-0.6.49#python setup.py Install
#distribute--version

5. Install PIP Package Management tool

Related websites:

Pip

#easy_install pip
#pip--version

6, Installation Uwsgi

Related websites:

Uwsgi

Uwsgi parameter explanation

#pip Install Uwsgi#uwsgi--version

7, Installation Virtualenv

Related websites:

Virtualenv

#pip Install virtualenv#virtualenv--version

8, installation Flask

Related websites:

Flask

#mkdir/usr/share/nginx/www                             //New Project Library folder
#mkdir/usr/share/nginx/www.a.com //New Project root folder
#cd/usr/share/nginx/www/www.a.com
#vietualenv env //Create a virtual environment
#. Env/bin/activate //Enter virtual environment
#pip Install flask //Installation flask
#deactivate //exit the virtual environment

9. Environment configuration

9.1 Configuration Declarations

First I want to declare the absolute location of several fixed directories. (This section is configured in strict accordance with the following location & if you need to modify the path, modify the relevant configuration file)

Nginx configuration file:/etc/nginx/vhosts/www.a.com.conf

#mkdir/etc/nginx/vhosts                                //New Nginx Configuration folder

Project root directory:/usr/share/nginx/www/www.a.com

Log file directory:/usr/share/nginx/log

#mkdir/usr/share/nginx/log                             //new log folder

Uwsgi configuration file:/etc/uwsgi/www.a.com.ini

#mkdir/etc/uwsgi                                       //New UWSGI Configuration folder

9.2 Configuring UWSGI

9.2.1 New UWSGI configuration file

#vi/etc/uwsgi/uwsgi_www.a.com.ini//New UWSGI configuration file

Enter the blue content below into the Wusgi_www.a.com.ini file

[Uwsgi]
Master = True
Vhost = True
workers = 2
Reload-mercy = Ten
Vacuum = True
max-requests = +
Limit-as =
chmod-socket = 666
socket =/tmp/uwsgi_www.a.com.sock
venv =/usr/share/nginx/www/www.a.com/env
chdir =/usr/share/nginx/www/www.a.com
module = MyApp
callable = App
touch-reload =/usr/share/nginx/www/www.a.com
pidfile =/var/run/uwsgi_www.a.com.pid
daemonize =/usr/share/nginx/log/uwsgi_www.a.com.log

9.2.2 Adding a boot script to Uwsgi

#vi/etc/init.d/uwsgi_www.a.com
Enter the blue content below into the uwsgi_www.a.com file
#! /bin/sh# chkconfig:2345 25# description:startup script for Uwsgi webserver on Debian. Place in/etc/init.d and# Run ' update-rc.d-f uwsgi defaults ', or with the appropriate command on your# distro. For Centos/redhat run: ' Chkconfig--add Uwsgi ' # # # BEGIN INIT info# provides:uwsgi# required-start: $all # Requ Ired-stop: $all # default-start:2 3 4 * default-stop:0 1 6# short-description:starts the UWSGI web server# Description:starts Uwsgi using start-stop-daemon### END INIT infopath=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/u sr/sbin:/usr/bindesc= "Uwsgi Daemon" name=uwsgi_www.a.comdaemon=/usr/local/bin/uwsgiconfigfile=/etc/uwsgi/$ name.inipidfile=/var/run/$NAME. pidscriptname=/etc/init.d/$NAMEset-e[-X "$DAEMON"] | | Exit 0do_start () {$DAEMON $CONFIGFILE | | echo-n "UWSGI already Running"}do_stop () {$DAEMON--stop $PIDFILE | | echo-n "UW SGI not running "rm-f $PIDFILEecho" $DAEMON stoped. "} Do_reload () {$DAEMON--reload $PIDFILE | | echo-n "UWSGI can"T Reload "}do_status () {PS Aux|grep $DAEMON}case" $ "instatus) echo-en" status $NAME: \ n "do_status; Start) Echo-en "starting $NAME: \ n" Do_start;; Stop) Echo-en "stopping $NAME: \ n" do_stop;; reload|graceful) Echo-en "reloading $NAME: \ n" do_reload; *) echo "Usage: $SCRIPTNAME {start|stop|reload}" >&2exit 3;; Esacexit 0

#chkconfig--add uwsgi_www.a.com//Add service
#chkconfig uwsgi_www.a.com on//Set boot up

9.2.3 modifying Nginx configuration files

First open the Nginx configuration file:

#vi/etc/nginx/nginx.conf

Find to:

include/etc/nginx/conf.d/*.conf;

Modified to:

#include/etc/nginx/conf.d/*.conf;                         Add a # sign at the beginning of the line comment out this sentence
include/etc/nginx/vhosts/*.conf; Referencing the app configuration file

9.2.4 New project configuration file

#vi/etc/nginx/vhosts/www.a.com.conf

Enter the blue content below into the uwsgi_www.a.com file

server {Listen 80; server_name www.a.com;
Index index.htm index.html;          Location/{include uwsgi_params; Uwsgi_pass Unix:///tmp/uwsgi_www.a.com.sock;
}}

10. Testing

10.1 Open Service

#service nginx start#service uwsgi_www.a.com start

10.2 New Portal Component files

#vi/usr/share/nginx/www/www.a.com/myapp.py//The following blue contents into the uwsgi_www.a.com file from flask import Flaskapp = Flask (__name__) @app. Route ('/') def hello_world (): Return ' Hello world!  ' if __name__ = = ' __main__ ': App.run ()

"Hello world!" appears when running browser access www.a.com Indicates that the environment has been successfully built.

Ps:

1, code word too much inevitably error, if found wrong or have questions please leave a message, I reply to you the first time.

2, this blog Welcome to forward, but please keep the following information:

By:oyy URL: date:2015 Year January 14

original link:http://localhost:8090/search/142294.html

Centos+nginx+uwsgi+virtualenv+flask Multi-site environment construction

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.