Nginx
基本命令
# 测试配置文件是否正确
nginx -t
# 重启/查看/停止
systemctl restart nginx
systemctl status nginx
systemctl stop nginx
# log
cat /var/log/nginx/error.log
cat /var/log/nginx/access.log
# ---------------------------------
# conf
/etc/nginx/nginx.conf
# 在该文件夹下添加配置文件
/etc/nginx/sites-available/
# 将sites-available文件夹中的配置文件软链到这里生效
/etc/nginx/sites-enabled/
# 配置时补充绝对路径
ln -s /etc/nginx/sites-available/site_nginx.conf /etc/nginx/sites-enabled/
# ---------------------------------
# uwsgi
/etc/nginx/uwsgi_params 中包含了一些标准的配置信息
部署Django
请求逻辑:http请求 -> nginx -> uwsgi -> web应用
-
安装uwsgi
pip安装的可以直接用(要使用venv环境),不用再配置。其他方法安装应该还要配置python。
-
设置当前用户权限 检查用户以及用户组,保证启动uwsgi和创建相关配置时拥有权限。可以将其加入www-data用户组。
-
uwsgi配置文件
-
添加nginx配置文件
# vim /etc/nginx/sites-available/mysite.conf # mysite_nginx.conf # the upstream component nginx needs to connect to upstream django { server unix:///etc/nikki_web/nikki.sock; # for a file socket # server 127.0.0.1:8001; # for a web port socket (we'll use this first) } # configuration of the server server { # the port your site will be served on listen 10080; # the domain name it will serve for # server_name 47.97.7.143; # substitute your machine's IP address or FQDN charset utf-8; # max upload size client_max_body_size 75M; # adjust to taste # Django media # location /media { # alias /path/to/your/mysite/media; # your Django project's media files - amend as required # } location /static { alias /var/www/nikki_web/static; # your Django project's static files - amend as required } # Finally, send all non-media requests to the Django server. location / { uwsgi_pass django; include /etc/nginx/uwsgi_params; # the uwsgi_params file you installed } }
-
创建软链
-
检查nginx配置文件
-
启动uwsgi
-
SSL