遇坑的同鞋能夠留意一下html
操做系統:Centos7python
準備文件:
Python-2.7.13.tgz
下載地址:https://www.python.org/ftp/python/2.7.13/Python-2.7.13.tgz
nginx-1.12.0.tar.gz
下載地址:http://nginx.org/download/nginx-1.12.0.tar.gz
uwsgi-2.0.15.tar.gz
下載地址:https://projects.unbit.it/downloads/uwsgi-2.0.15.tar.gznginx
一、安裝Python
configure注意帶參數--with-zlib,不然uwsgi會報錯
tar -zxvf Python-2.7.13.tgz
cd Python-2.7.13
./configure --with-zlib
make
make install
make cleanweb
python --version 能夠查看版本
修改版本會致使一些小問題,能夠嘗試修改#!/usr/bin/python爲#!/usr/bin/python2.7app
二、安裝配置nginx
安裝沒什麼特別的
tar -zxvf nginx-1.12.0.tar.gz
cd nginx-1.12.0
./configure
make
make install
make cleanpython2.7
配置
若是沒有自定義安裝路徑
nginx.conf文件默認路徑爲/usr/local/nginx/conf/nginx.conf
若是用yum安裝配置路徑爲/etc/nginx/nginx.conf
能夠試着查找
find /|grep nginx.conf
whereis nginx
修改nginx.conf 文件,沒必要擔憂改壞了,同目錄下還有個nginx.conf.default
若是80端口有其它用處,能夠把listen 80;改爲其它端口,避免衝突
內容不妨先仿着server再寫一個server與原來的server保持並列,
server {
listen 2001;
server_name [::]:2001 localhost;
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:8080;
}
}
listen應該是監聽,那麼從外部訪問應該訪問2001端口
uwsgi_pass 127.0.0.1:8080;這句與proxy_pass看起來很像,向內轉發數據,而且須要在8080端口上有監聽,uwsgi會處理這事curl
啓動nginx
/usr/local/nginx/sbin/nginx
能夠帶配置文件,默認用/usr/local/nginx/conf/nginx.confsocket
試着訪問一下x.x.x.x:80與x.x.x.x:2001ui
三、寫一個test.py
暫且放在/var/test/路徑下
#!/usr/bin/python2.7
# -*- coding:utf-8 -*-
# test.py
import web
urls = (
'/', 'index'
)
class index:
def GET(self):
return 'Hello, world!'
app = web.application(urls,globals())
# app.run()
application = app.wsgifunc()
若是沒有web模塊能夠先pip install web.py
試試會不會報錯python code.pyurl
四、安裝配置uwsgi
這裏有更詳細的說明
http://uwsgi-docs.readthedocs.io/en/latest/Install.html
tar -zxvf uwsgi-2.0.15.tar.gz
cd uwsgi-2.0.15
python uwsgiconfig.py --build
配置文件
支持多種格式,這裏用ini
爲code.py寫一個配置文件test.uwsgi.ini
[uwsgi]
socket = 127.0.0.1:8080 #與nginx的uwsgi_pass對應
chdir = /var/test/
wsgi-file = test.py
processes = 4
threads = 2
stats = 127.0.0.1:2011
daemonize = ./uwsgi.log
啓動
./uwsgi --wsgi-file test.uwsgi.ini
若是正常的話
curl x.x.x.x:2001
將會返回Hello,world
不然能夠到uwsgi.log中查看錯誤信息
查看端口占用
lsof -i:80
在記事本中寫了貼過來,格式有點問題,懶得改了