先安裝如下的軟件(若是有的話,就能夠不安裝了,例如使用rpm -qa zlib-devel先查看下)
yum install zlib-devel -y
yum install openssl-devel -yhtml
tar -zxvf解壓
./configure --prefix=/usr/local/python #安裝到/usr/local/python目錄下。
make
make installpython
先安裝pcre-devel:
yum install pcre-devel -ynginx
./configure --prefix=/usr/local/nginx
make && make installflask
cat /usr/local/nginx/conf/nginx.confbash
#user nobody; worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; sendfile on; keepalive_timeout 65; server { listen 8080; access_log /usr/local/nginx/logs/flask_access.log main; error_log /usr/local/nginx/logs/flask_error.log error; client_max_body_size 200M; location / { include uwsgi_params; uwsgi_pass unix:/dev/shm/uwsgi.sock; index index.html index.htm; } } }
啓動nginx:
/usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx網絡
注意:uwsgi_pass unix:/dev/shm/uwsgi.sock;須要和uwsgi的配置相對應!app
[uwsgi] uid = root gid = root socket = /dev/shm/uwsgi.sock chmod-socket = 666 enable-threads = true master = true plugins = /usr/local/python/bin/python vhost = true workers = 5 max-requests = 1000 pidfile = /var/run/uwsgi.pid daemonize = /var/log/uwsgi.log chdir = /root/ops_dev/ module = ops_dev callable = app
啓動uwsgi,有些報錯沒什麼事:
/usr/local/python/bin/uwsgi /root/uwsgi.ini
socket
cat /root/ops_dev/ops_dev.py測試
# -*- coding: UTF-8 -*- from flask import Flask app = Flask(__name__) @app.route('/', methods=['GET', 'POST']) def index(): return 'Hello world,Python ops_dev!'
編寫完須要重啓uwsgi,開改動代碼都須要重啓uwsgi,直接使用pkill進行重啓便可:
pkill uwsgi
訪問http://localhost:8080/進行測試。
訪問日誌記錄(nginx和uwsgi的訪問日誌,可用來排錯。):
ui
最後附上本人的網絡課堂地址,若有興趣請點擊: 實踐哥