我们只需要修改nginx配置
if ($server_port !~ 443){
rewrite ^(/.*)$ https://$host$1 permanent;
}
完整配置示例:
server {
listen 80;
listen 443 ssl http2;
server_name xxx.cn www.xxx.cn;
index index.php index.html index.htm default.php default.htm default.html;
root /www/test/xxx;
ssl_certificate /www/test/xxx.pem;
ssl_certificate_key /www/test/xxx.key;
ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
ssl_ciphers EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
add_header Strict-Transport-Security "max-age=31536000";
# 自动将所有80端口上的请求重定向到HTTPS
if ($server_port !~ 443) {
rewrite ^(/.*)$ https://$host$1 permanent;
}
location / {
proxy_pass http://127.0.0.1:3000/;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header HTTP_X_FORWARDED_FOR $remote_addr;
proxy_redirect off;
proxy_buffering off;
}
access_log /www/test/xxx.com.log;
error_log /www/test/xxx.com.error.log;
}
评论(0)