Django项目中的配置
配置域名访问
upstream django {
server 127.0.0.1:8000;
}
server {
listen 80;
server_name 域名地址 公网IP;
charset utf-8;
client_max_body_size 75M;
location /media {
alias /django项目路径/media;
}
location /static {
alias /django项目路径/static;
}
location / {
uwsgi_pass django;
include uwsgi_params;
}
}
配置SSL证书
upstream django {
server 127.0.0.1:8000;
}
server {
listen 80;
server_name 域名地址 公网IP;
charset utf-8;
client_max_body_size 75M;
listen 443 ssl;
server_name 域名地址;
root django项目路径;
ssl_session_timeout 5m;
ssl_certificate /etc/nginx/1_xxx_bundle.crt;
ssl_certificate_key /etc/nginx/2_xxx.key;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
fastcgi_connect_timeout 300s;
fastcgi_send_timeout 300s;
fastcgi_read_timeout 300s;
location /media {
alias /django项目路径/media;
}
location /static {
alias /django项目路径/static;
}
location / {
uwsgi_pass django;
include uwsgi_params;
}
}
注意:要先把下载好的ssl证书中的nginx文件中的两个文件拷贝到服务器的/etc/nginx目录下。
配置http重定向https
upstream django {
server 127.0.0.1:8000;
}
server {
server_name 域名地址 公网IP;
charset utf-8;
client_max_body_size 75M;
listen 443 ssl;
server_name 域名地址;
root django项目路径;
ssl_session_timeout 5m;
ssl_certificate /etc/nginx/1_xxx_bundle.crt;
ssl_certificate_key /etc/nginx/2_xxx.key;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
fastcgi_connect_timeout 300s;
fastcgi_send_timeout 300s;
fastcgi_read_timeout 300s;
location /media {
alias /django项目路径/media;
}
location /static {
alias /django项目路径/static;
}
location / {
uwsgi_pass django;
include uwsgi_params;
}
}
server {
listen 80;
server_name 域名地址;
return 301 https://$host$request_uri;
}
注意:必须注释掉上面的 listen 80;
|