1024programmer Nginx CentOS system installs Nginx+Uwsgi server environment

CentOS system installs Nginx+Uwsgi server environment

The most troublesome thing about using Python as a web application is to configure the server environment. It is not as easy as PHP to configure and then throw the .php file into the web directory. And the current configuration of python
There are also many methods for the web environment, which is really frustrating for novices. Here is a record of the nginx+uwsgi environment I compiled and configured on CentOS.

Get ready
Update the system first, and install the compilation environment and so on.
yum update
yum install python python-devel libxml2 libxml2-devel python-setuptools zlib-devel wget openssl-devel pcre pcre-devel sudo gcc make autoconf automake

Compile and install uwsgi
The official website of uwsgi is http://projects.unbit.it/uwsgi/, here we download its current stable version.
wget http://projects.unbit.it/downloads/uwsgi-1.0.4.tar.gz
tar -zxvf uwsgi-1.0.4.tar.gz # decompress
mv uwsgi-1.0.4 uwsgi # Renamed to uwsgi, just for convenience
cd uwsgi # switch to uwsgi directory
python setup.py build # compile and install
make
Next, move the compiled executable file to /usr/bin

Compile and install nginx
The official website of nginx is http://nginx.org, here we still download its stable version.
cd ~
wget http://nginx.org/download/nginx-1.0.13.tar.gz
tar -zxvf nginx.1.0.13.tar.gz
mv nginx-1.0.13 nginx
cd nginx
./configure –prefix=/usr/local/nginx # Compilation option configuration, simplified here
make && make install # compile and install
Let’s create a soft link for the generated nginx executable file in /usr/sbin
ln -s /usr/local/nginx/sbin/nginx /usr/sbin/nginx

Configure nginx
use vi
/usr/local/nginx/conf/nginx.conf Open the nginx configuration file, and add/modify the following content to the server (as for the use of vi/vim, uh, learn by yourself):
location /{
uwsgi_pass 127.0.0.1:9001;
include uwsgi_params;
}
ESC, enter: wq to save and exit.

Test
Taking Flask as an example here, the simple way to install Flask is (provided that pip has been installed):
pip install flask
For convenience, create a new file myapp.py in /usr/share here
from flask import Flask
app = Flask(__name__)
app.debug = True
@app.route(‘/’)
def index():
return ‘Hello World!’
Then we start nginx and uwsgi:
nginx
cd /usr/share
uwsgi -s 127.0.0.1:9001 -w myapp:app -d /var/log/uwsgi.log
Then open the localhost in the browser, if you see the big evil Hello World!, it means the configuration is successful!

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/centos-system-installs-nginxuwsgi-server-environment/

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索