- 上线前的检查
python [图片上传失败...(image-d41cc-1579252119950)]
manage.py check --deploy
保持HTTPS连接的时间
SECURE_HSTS_SECONDS = 3600
SECURE_HSTS_INCLUDE_SUBDOMAINS = True
SECURE_HSTS_PRELOAD = True
自动重定向到安全连接
SECURE_SSL_REDIRECT = True
避免浏览器自作聪明推断内容类型
SECURE_CONTENT_TYPE_NOSNIFF = True
避免跨站脚本攻击
SECURE_BROWSER_XSS_FILTER = True
COOKIE只能通过HTTPS进行传输
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
防止点击劫持攻击手段 - 修改HTTP协议响应头
当前网站是不允许使用<iframe>标签进行加载的
X_FRAME_OPTIONS = 'DENY'
创建项目文件夹
mkdir -p ~/project/{code, conf, logs, stat}
cd project克隆项目到code文件夹
cd code
git clone --depth=1 git@gitee.com:jackfrued/blog.git创建虚拟环境重建依赖项
cd ..
pip3 install virtualenv
virtualenv --python=/usr/bin/python3 venv
source venv/bin/activate
pip install -r code/blog/requirements.txt
pip install uwsgi编写uWSGI的配置文件 - conf/uwsgi.ini
[uwsgi]
配置前导路径
base=/root/project
配置守护进程
master=true
配置进程数
processes=4
虚拟环境路径
pythonhome=%(base)/venv
项目路径
chdir=%(base)/code/blog
指定python解释器
pythonpath=%(pythonhome)/bin/python
指定wsgi文件对应的模块
module=blog.wsgi
通信的地址和端口(自己服务器的IP地址和端口)
socket=[图片上传失败...(image-ab35dd-1579252119949)]
172.18.61.250:80
日志文件地址
logto=%(base)/logs/uwsgi.log
启动uWSGI
uwsgi --ini conf/uwsgi.ini &动静分离部署
yum install -y nginx
vim /etc/nginx/nginx.conf
全局Nginx配置文件 - /etc/nginx/nginx.conf
user root;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
include /usr/share/nginx/modules/.conf;
events {
worker_connections 1024;
}
http {
log_format main 'remote_user [request" '
'body_bytes_sent "http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 30;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
include /etc/nginx/conf.d/.conf;
include /root/project/conf/nginx.conf;
}
局部配置 - conf/nginx.conf
server {
listen 80;
server_name _;
root /root/project/stat/html;
location /api/ {
include uwsgi_params;
uwsgi_pass [图片上传失败...(image-a33e0d-1579252119948)]
172.18.61.250:8000;
}
location /upload/ {
include uwsgi_params;
uwsgi_pass [图片上传失败...(image-daf6ac-1579252119948)]
172.18.61.250:8000;
}
location /media/ {
alias /root/project/code/blog/media/;
expires 30d;
}
location /static/ {
alias /root/project/stat/;
expires 30d;
}
}
修改配置文件 - code/blog/blog/[图片上传失败...(image-9143b1-1579252119948)]
settings.py
STATIC_ROOT = '/root/project/stat/'
收集静态资源 - code/blog
python [图片上传失败...(image-68283-1579252119948)]
manage.py collectstatic
启动Nginx
systemctl start nginx
-
部署HTTPS
server {
listen 443 ssl;
server_name _;ssl_certificate /root/project/cert/jackfrued.top.pem;
ssl_certificate_key /root/project/cert/jackfrued.top.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;root /root/project/stat/html;
location /api/ {
include uwsgi_params;
uwsgi_pass [图片上传失败...(image-5eea52-1579252119947)]
172.18.61.250:8000;
}
location /upload/ {
include uwsgi_params;
uwsgi_pass [图片上传失败...(image-978528-1579252119947)]
172.18.61.250:8000;
}
location /media/ {
alias /root/project/code/blog/media/;
expires 30d;
}
location /static/ {
alias /root/project/stat/;
expires 30d;
}
}