1、什么是Nginx
nginx其实也是一个web服务器,它是一个代理服务器,
客户端的请求必须经过nginx,然后nginx再将请求中
的动态请求转发给上游的web服务器
2、Nginx的安装
apt-get update
apt-get install nginx
3、Nginx的启动
a、加载配置: nginx -c /etc/nginx/nginx.conf
b、重启Nginx: nginx -s reload
c、验证:访问80端口,是否显示默认的html界面
4、Nginx反向代理配置
在/etc/nginx/conf.d/文件夹下创建配置文件xxx.conf
配置内容
server {
listen 80; # 监听端口
server_name localhost; # 监听地址
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:8080; # 转发地址
#proxy_pass http://www.baidu.com;
index index.html index.htm;
client_max_body_size 35m;
}
}
配置代理后,执行nginx -t 验证语法是否有问题
nginx -s reload 重新加载配置,重启nginx服务
5、什么是uwsgi
uWSGI是一个Web服务器,它实现了WSGI协议、uwsgi、http等协议。Nginx中HttpUwsgiModule的作用是与uWSGI服务器进行交换。
要注意 WSGI / uwsgi / uWSGI 这三个概念的区分。
WSGI是一种通信协议。
uwsgi是一种线路协议而不是通信协议,在此常用于在uWSGI服务器与其他网络服务器的数据通信。
而uWSGI是实现了uwsgi和WSGI两种协议的Web服务器。
6、uwsgi的安装
https://www.runoob.com/python3/python-uwsgi.html
安装依赖包 apt-get install build-essential python-dev
安装uwsgi root账号下执行 pip install uwsgi
7、启动uwsgi服务
单独启动:uwsgi --http :9090 --wsgi-file foobar.py
和Nginx配合使用:uwsgi --socket :9090 --wsgi-file foobar.py
与Nginx配合使用,参数是 --socket
8、Nginx+uwsgi+flask项目的启动
uwsgi --socket 127.0.0.1:8080 --wsgi-file main.py --callable app --processes 4 --threads 2
如果启动的不是app项目,-callable app需要去掉