nginx http强制跳转https

1.按照如下格式修改nginx.conf 配置文件,80端口会自动转给443端口,这样就强制使用SSL证书加密了。

访问http的时候会自动跳转到https上面。

server {

listen 80;

server_name www.域名.com;

rewrite ^(.*) https://$server_name$1 permanent;

}

server {

listen 443;

server_name www.域名.com;

root /home/www;

ssl on;

ssl_certificate /etc/nginx/certs/server.crt;

ssl_certificate_key /etc/nginx/certs/server.key;

}

2.Nginx实现同一端口HTTP跳转HTTPS

error_page 497 https://$host:$server_port$uri$is_args$args;

nginx   http强制跳转https

相关推荐