Debian System Python+uwsgi+nginx Implement Web environment

Source: Internet
Author: User


1,python implementation of the Web deployment:

Python+uwsgi+nginx implements the Web.


This article tests the environment:

Server: Raspberry Pi B +

Operating system:

[Email protected]:~# cat/etc/issueraspbian Gnu/linux 7 \ n \l

Ip:

[Email protected]:~# IP ad s1:lo: <LOOPBACK,UP,LOWER_UP> MTU 65536 qdisc noqueue State UNKNOWN link/loopback 00 : 00:00:00:00:00 BRD 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever Preferred_lft Forever2:et H0: <BROADCAST,MULTICAST,UP,LOWER_UP> MTU Qdisc Pfifo_fast State up Qlen, Link/ether b8:27:eb:ed:b8:e5 b Rd FF:FF:FF:FF:FF:FF inet 192.168.137.100/24 BRD 192.168.137.255 scope global eth0 Valid_lft forever PREFERRED_LF T forever

Software Requirements:

python2.7.3

django-1.7.2

rpyc-3.3.0

uwsgi-2.0.9

nginx-1.6.2

mysql-5.5.40

Are the latest versions of the current stable version.


2, create the appropriate directory:

[Email protected]:~# mkdir/data[email protected]:~# mkdir/data/logs #所有日志存放位置 [email protected]:~# mkdir/data/www #页面代码 [e-mail protected]:~# mkdir/data/server #软件安装位置, behind Nginx seemingly installed under/data, this directory is useless. [Email protected]:~# mkdir/soft #下载软包位置


3. Install the necessary packages

# apt-get update# update under the system to install the appropriate library files, some systems and installed will not have to reinstall: # apt-get Install Libpcre3-dev Libssl-dev libpcre3 Libssl Build-essential zlib1g zlib1g-devbuild-essential #可以解决包间的依赖关系等, it is important to Raspbian the default installation.


-----------------------Installing Nginx--------------------------

Download the package:

# cd/soft/# wget http://nginx.org/download/nginx-1.6.2.tar.gz

Create Nginx run users and groups:

# groupadd-g www# useradd-u 5000-g, www# tar-zxf nginx-1.6.2.tar.gz# cd nginx-1.6.2/#./configure--prefix=/d Ata/nginx--user=www--group=www--with-http_stub_status_module##--with-http_stub_status_module #启用Nginx状态监控模块, Default does not open. # make# make Install


-----------------------install MySQL--------------------------

# Aptitude Search Mysql|grep ^i# Check the system for MySQL corresponding package, have delete # Apt-get remove mysqlxxx# system comes with MySQL related package # Apt-get install Mysql-server mysql-client python-mysqldb (python link mysql support package) #默认会安装许多依赖包 and will let you set the MySQL root account password.

The default installation completes automatically start, test:

# mysql -uroot -penter password: welcome to the mysql monitor.   commands end with ; or \g.your mysql connection id is  43Server version: 5.5.40-0+wheezy1  (Debian) copyright  (c)  2000, 2014,  Oracle and/or its affiliates. all rights reserved. oracle is a registered trademark of oracle corporation and/or  Itsaffiliates. other names may be trademarks of their respectiveowners . type  ' help; '  or  ' \h '  for help. Type  ' \c '  to clear the current input  statement.mysql> show databases;+--------------------+| database            |+--------------------+| information_schema | |  mysql              | |  performance_schema |+--------------------+3 rows in set  (0.00 sec)


To test whether the PYTHON-MYSQLDB was installed successfully:

[Email protected]:~# pythonpython 2.7.3 (default, Mar, 05:13:23) [GCC 4.6.3] on Linux2type ' help ', ' copyright ', ' C Redits "or" license "for more information.>>> import mysqldb>>>

No error is successful.

-----------------------Installing the RPYC--------------------------

The RPYC module is used by the platform to interact with the host terminal for data communication and get the latest version: HTTPS://PYPI.PYTHON.ORG/PACKAGES/SOURCE/R/RPYC

# cd/soft/# wget https://pypi.python.org/packages/source/r/rpyc/rpyc-3.3.0.tar.gz# tar-zxf rpyc-3.3.0.tar.gz# CD rpyc-3.3.0/# python setup.py Install

No error is successful.

-----------------------Installing the Uwsgi--------------------------

# # # TAR Package Installation:

Get the latest version: Http://uwsgi-docs.readthedocs.org/en/latest/Download.html

Baidu Encyclopedia can be found in the relevant information Uwsgi.

# apt-get Install Python-dev #编译时需要python相关库文件 # cd/soft# wget http://projects.unbit.it/downloads/uwsgi-2.0.9.tar.gz# t AR-ZXF uwsgi-2.0.9.tar.gz# cd uwsgi-2.0.9/# python uwsgiconfig.py--build #看服务器配置, the wait time may be longer. # # # Apt-get Source Installation # Apt-get install uwsgi# This installation resolves package dependencies without worrying about the installation encountering a dependency package error.

See the following code to indicate that the installation was successful:

[OK] Starting app Server (s): Uwsgi (omitted; missing Conffile (s) in/etc/uwsgi/apps-enabled).

-----------------------to install the Django--------------------------

Reference: http://chongzi100.blog.51cto.com/340243/1600754

Version: Django-1.7.2


4, create a Django project:

# cd/data/www/# django-admin startproject web04# Tree web04web04├──manage.py└──web04├──__init__.py├──settings . py├──urls.py├──wsgi.py1 directory, 5 files

Django Test, you can see the reference article.


5, configure Nginx:

# pwd/data/nginx/conf# cat nginx.confuser  www;worker_processes  1;pid  /data/logs/nginx/nginx.pid;events {    worker_connections  1024;} http {    include       mime.types;     default_type  application/octet-stream;    sendfile         on;    keepalive_timeout  65;     gzip  on;    server {         listen       80;         server_name  web01.test.com;        location / {             uwsgi_pass 192.168.137.100:8000;             uwsgi_param uwsgi_chdir  /data/www/web04/web04;             uwsgi_param UWSGI_SCRIPT wsgi;             include uwsgi_params;             access_log /data/logs/nginx_access.log;      #打开日志功能方便排错.         }    }}

6, configuring UWSGI, creating Uwsgi configuration file/data/nginx/conf/uwsgi.ini

# cat Uwsgi.ini [UWSGI] socket = 192.168.137.100:8000master = True Pidfile =/data/logs/uwsgi.pid processes = 4 #指定  Number of processes workers = 1 #分配CPU核数chdir =/data/www/web04/web04 #项目主目录pythonpath =/data/www/web04 #项目上层目录profiler = True     Memory-report = True Enable-threads = True Logdate = True Limit-as = #内存限制512kdaemonize =/data/logs/django.log #开启日志, easy to debug gid = Wwwuid = Wwwvhost = False #如果是多站点, can be changed to Trueplugins = Python #指定uwsgi将使用python


For more parameter descriptions, refer to the official instructions.


Http://uwsgi-docs.readthedocs.org/en/latest/Configuration.html


7, Test:

Start Uwsgi:uwsgi--ini/data/nginx/conf/uwsgi.ini start Nginx:/data/nginx/sbin/nginx

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/58/D5/wKioL1S-FsTQMXccAAFpYByxf8E807.jpg "style=" float: none; "title=" 1.png "alt=" Wkiol1s-fstqmxccaafpybyxf8e807.jpg "/>

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/58/D8/wKiom1S-FfDzWDaIAAFOaMaiuVk905.jpg "style=" float: none; "title=" 2.png "alt=" Wkiom1s-ffdzwdaiaafoamaiuvk905.jpg "/>

8, Error encountered:

"unavailable modifier requested"

This error was searched online, mostly because the uwsgi configuration file could not find python .


Workaround:

Verify that the Uwsgi-plugin-pythonis installed:

# aptitude Search Uwsgi-plugin-pythoni Uwsgi-plugin-python-python WSGI plugin for Uwsgi p Uwsgi-plugi N-python3-python 3 WSGI plugin for UWSGI

Two parameters all represent the current state of the package.

I #表示已安装

P #表示清除软件包


To modify a configuration file:

# vim Uwsgi.ini plugins = Python #添加该行, specify Uwsgi with Python


9, concluding remarks:

The text does not do Python again to link MySQL test, in a future article write it. If there is something wrong, please leave a message to me.

This article is from the "Bug" blog, please be sure to keep this source http://chongzi100.blog.51cto.com/340243/1606216

Debian System Python+uwsgi+nginx Implement Web environment

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.