http跳转https实现示例:
ssl配置参考“https”实现文章
法一:2个虚拟主机
配置: [[email protected] certs]# vim /apps/nginx4/conf/conf.d/test.conf server { listen 443 ssl; # listen 80; server_name www.magedu.org; root /data/site14/; #ssl on; ssl_certificate /apps/nginx4/ssl/magedu.org.crt; ssl_certificate_key /apps/nginx4/ssl/magedu.org.key; ssl_session_cache shared:sslcache:20m; ssl_session_timeout 10m; access_log /apps/nginx4/logs/magedu.org.ssl.access.log access_json ; } server { listen 80; server_name www.magedu.org; access_log /apps/nginx4/logs/magedu.org.access.log access_json; #最好和https的日志文件一样 location / { rewrite ^/(.*)$ https://www.magedu.org/$1 permanent; #不写permanent/redirect,默认是redirect } } 验证: [[email protected] certs]# curl -I http://www.magedu.org/ HTTP/1.1 301 Moved Permanently Server: nginx/1.14.2 Date: Mon, 08 Mar 2021 07:00:55 GMT Content-Type: text/html Content-Length: 185 Connection: keep-alive Location: https://www.magedu.org/
法二:1个虚拟主机
配置: [[email protected] certs]# vim /apps/nginx4/conf/conf.d/test.conf server { listen 443 ssl; listen 80; server_name www.magedu.org; root /data/site14/; #ssl on; ssl_certificate /apps/nginx4/ssl/magedu.org.crt; ssl_certificate_key /apps/nginx4/ssl/magedu.org.key; ssl_session_cache shared:sslcache:20m; ssl_session_timeout 10m; access_log /apps/nginx4/logs/magedu.org.ssl.access.log access_json ; location /{ if ($scheme = http) { rewrite ^/(.*)$ https://www.magedu.org/$1 permanent; #不写permanent/redirect,默认是redirect } } } 验证: [[email protected] certs]# curl -I http://www.magedu.org/ HTTP/1.1 301 Moved Permanently Server: nginx/1.14.2 Date: Mon, 08 Mar 2021 07:06:51 GMT Content-Type: text/html Content-Length: 185 Connection: keep-alive Location: https://www.magedu.org/
标签:www,http,ssl,apps,magedu,access,nginx,跳转,org From: https://www.cnblogs.com/cnblogsfc/p/14591975.html