事件:部署了一个项目,发现浏览器输入网址,浏览器识别是http的,而我的网站配置了ssl 且只有https的时候才能访问,于是需要重定向 是监听80端口的网站重新定向到https,实现http自动跳转https
解决:重新配置nginx
cd /etc/nginx/conf.d
sudo vim order.conf
server {
listen 80;
server_name 网址;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
server_name 网址;
ssl on;
ssl_certificate /data/www/https/chained.pem;
ssl_certificate_key /data/www/https/domain.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA;
ssl_session_cache shared:SSL:50m;
location /static {
alias /data/www/orderAll/web/static/;
}
location /.well-known/acme-challenge/ {
alias /data/www/challenges/;
try_files $uri =404;
}
location / {
try_files $uri @yourapplication;
}
location @yourapplication {
include uwsgi_params;
uwsgi_pass unix:/data/www/logs/order.sock;
}
}
重新加载nginx
sudo service nginx reload
网友评论