3.1 安装 Nginx
sudo apt install nginx
3.2 修改 nginx.conf
- 切换到 nginx 目录下
cd /etc/ngnix
- nginx.conf 文件内容如下 ( 修改文件相应部分 , 或 直接清空文件 完全复制以下内容 )
user root; worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80 default_server; server_name _; return 404; } server { listen 80; server_name 你的域名 www.你的域名; #省略www也要写 下面要做301跳转 if ($host = "你的域名" ) { rewrite ^/(.*)$ http://www.你的域名/$1 permanent; #301跳转 } charset utf-8; location / { gzip on; #gzip网站压缩 gzip_http_version 1.1; gzip_comp_level 3; gzip_types text/plain application/json application/x-javascript application/css application/xml application/xml+rss text/javascript application/x-httpd-php image/jpeg image/gif image/png image/x-ms-bmp; include uwsgi_params; #主要添加这个 uwsgi_connect_timeout 30; uwsgi_pass unix:/home/ubuntu/你的项目文件夹/uwsgi.sock; #主要这个 index index.html index.htm; client_max_body_size 75M; } location /static { alias /home/ubuntu/你的项目文件夹/static;#主要这个 index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } }
3.3 启动 Nginx
sudo service nginx restart
- 正常运行后 , 浏览器输入你的域名进行测试 ( 不带 8000端口 )
3.3.1 附 Nginx相关命令
- 启动 / 重启 - sudo service nginx restart
- 查看进程 - sudo service nginx status
- 停止Nginx - sudo service nginx stop
此时 uWSGI + Nginx 配置已完毕 , 如需要配置 https 访问 ( 比如对接 微信小程序 ), 则进行下一步