什么是nginx
nginx是轻量级的高性能web服务器,提供了注入HTTP代理和反向代理、负载均衡等功能
路由过程
客户端请求nginx,再由nginx将请求转发uwsgi运行的django
安装
tar -zxvf nginx-1.13.7.tar.gz
cd nginx-1.13.7/
[root@zaishu nginx-1.13.7]# ./configure
.....
nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/nginx/sbin/nginx"
nginx modules path: "/usr/local/nginx/modules"
nginx configuration prefix: "/usr/local/nginx/conf"
nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
nginx pid file: "/usr/local/nginx/logs/nginx.pid"
nginx error log file: "/usr/local/nginx/logs/error.log"
nginx http access log file: "/usr/local/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"
make
install
配置
[root@zaishu www]#vi /usr/local/nginx/conf/nginx.conf
server {
listen 8996; #暴露给外部访问的端口
server_name localhost;
charset utf-8;
location / {
include uwsgi_params;
uwsgi_pass 0.0.0.0:8000; #外部访问8996就转发到内部8997
}
}
nginx -t 检查配置文件语法
启动模式变更为uwsig 协议
[root@zaishu www]# cat uwsgi.ini
[uwsgi]
scoket=0.0.0.0:8000
chdir=/root/www
wsgi-file=www/wsgi.py
process=4
threads=2
pidfile=uwsgi.pid
daemonize=uwsgi.log
master=True
[root@zaishu www]# uwsgi --ini uwsgi.ini
[uWSGI] getting INI configuration from uwsgi.ini
[root@zaishu www]# cd /usr/local/nginx
[root@zaishu nginx]# cd sbin/
[root@zaishu sbin]# ./nginx
访问80
用uwsgi 启动django之后,它就不管静态文件了。此时可以用nginx来加载静态文件。之前在将静态文件的时候,是让告诉那个runserver的。
再次访问,这些静态文件nginx 来处理了