python-a Web project developed using NGINX+UWSGI Deployment flask Framework on CENTOS7

Source: Internet
Author: User
Tags virtual environment virtualenv

First step: Prepare the CENTOS7 server

This deployment I was using in a virtual machine environment that was deployed to my native, so I installed CentOS7 on the VM first. To avoid a change in the IP address of each boot of the virtual machine server, first configure the static IP, first locate the virtual NIC configuration menu on the VM Workstation's menu bar, then remove the Adapter8 DHCP and then view the Gateway (Chinese name). In CentOS mainly involves the configuration of a file, in/etc/sysconfig/network_config/(network card number, similar to Cfg_eth0 file), and then edit 5 places:

1.bootproto=static Static IP

2.onboot=yes starts with the computer

3.netmask=255.255.255.0 Subnet Mask

4.gateway=192.168.3.2 gateways, same as the gateway previously viewed in the VM

4.ipaddr=192.168.3.7 need to be in the same network segment as the gateway

5.dns1=192.168.3.2 DNS and gateways are the same

Finally, enter the command service restart network to restart.


Step Two: Install Python

Because CentOS7 comes with python2.7.5, I'm not going to reinstall Python here, and if you need to install Python, you can find other information, you'll want to use make && makes when installing other versions of Python. Altinstall avoid overwriting previous versions of Python, causing other programs in the system to use the default version of Python to not run. Then install the PIP, I use the source installation, first go to the PIP official website to download the package of Pip, and then unzip, into the extracted directory, enter the Python setup.py install installed Pip, if prompted missing Setuptools module, Install the Setuptools module first, you can use Yum install, perform the Yum install Setuptools installation, you can use other installation methods, install the Setuptools after installing PIP,PIP installed, enter the project folder, Because my project has previously generated requirements files through Pip freeze >requirements.txt, you can use PIP Install-r requirements.txt directly to install the modules needed for your project when migrating to another environment. The installation of this Python environment is complete and you can start the project under Python to see if the Python environment is configured successfully.

If there may be multiple projects in different Python environments on the server, you can use Virtualenv to create a standalone Python environment, which can be installed by Pip and then executed under the project folder virtualenv venv Create a virtual environment. You can add the-no-site-packages parameter without copying the site-packages in the real Python environment to the new virtual environment to create a clean python environment.


Step three: Installing Nginx and Uwsgi

First go to the Nginx official website to download the source code, and then execute./configure && make && makes install, Nginx will be automatically added to the/usr/bin/nginx execution environment, The Nginx command can be executed directly, through the NGINX-C conf/nginx.conf (nginx configuration file) to start Nginx, After the successful start can be accessed 127.0.0.1来 Verify that Nginx is successful, the default port of Nginx is 80, can be configured through the Conf directory under the Nginx installation directory nginx.conf.

Then install the UWSGI, the same way to install the source code, after installation, you need to configure Nginx to pass all requests to UWSGI processing.

Configuration Nginx is very simple, edit the nginx.conf file, locate the server node under the Localtion,localtion/{

Include Uwsgi_params;

Uwsgi_pass 127.0.0.1:3031;

root HTML;

Index index.html index.htm

}

Then through Ps-ef | grep nginx found Nginx thread master thread number, and then through the Kill-hup nginx thread number Restart Nginx, this time again access to 127.0.0.1 will be wrong.

Next, configure Uwsgi, create the App_config.ini profile under the project folder, and the file name can be customized with the following:

[Uwsgi]

socket=127.0.0.1:8099

chdir=/var/www/my-website/#项目路径

Wsgi-file=manage.py #项目的启动的主文件, that is, app = Flask (__name__) creation file, here need to be flexible

Callable=app #这个就是app = App object name in Flask (__name__)

Processes=4 #配置启动多少个进程来处理请求

After configuration, start Uwsgi by Uwsgi App_config.ini, where the App_config.ini requires absolute or relative paths

After configuration, access to the 127.0.0.1 will be able to access the routing function of the routing address "/" in the project.


To this Python project on the success of the deployment, there are any problems to add, this article is completely blind write, some command or configuration name can be entered in error, if errors can be self-lookup.


This article is from the "Technology Not Home" blog, please be sure to keep this source http://chrischen.blog.51cto.com/9954795/1763802

python-a Web project developed using NGINX+UWSGI Deployment flask Framework on CENTOS7

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.