nginx http重定向https

现在什么苹果,谷歌浏览器请求地扯基本都要求使用https了,如何把原来的http协议重定向到https中呢,这里我们可以使用http反向代理软件nginx

配置

cat /usr/local/nginx/conf/vhost/gdmizi.com.conf

server {
 listen 80;
 server_name www.gdmizi.com gdmizi.com;
 return 301 https://$server_name$request_uri;
}

server{
 listen 443;
 #listen [::]:80;
 server_name www.gdmizi.com gdmizi.com;
 ssl on;
 index index.html index.htm index.php default.html default.htm default.php;
 root /mnt/website/gdmizi.com/wordpress;
 
 ssl_certificate /usr/local/nginx/cert/214404008820600.pem;
 ssl_certificate_key /usr/local/nginx/cert/214404008820600.key;
 ssl_session_timeout 5m;
 ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
 ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
 ssl_prefer_server_ciphers on;
 
 include wordpress.conf;
 #error_page 404 /404.html;
 include enable-php.conf;
 
 location ~ [^/]\.php(/|$)
 {
 # comment try_files $uri =404; to enable pathinfo
 try_files $uri =404;
 fastcgi_pass unix:/tmp/php-cgi.sock;
 fastcgi_index index.php;
 include fastcgi.conf;
 #include pathinfo.conf;
 }

 location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
 {
 expires 30d;
 }

 location ~ .*\.(js|css)?$
 {
 expires 12h;
 }

 location ~ /\.
 {
 deny all;
 }

 access_log /home/wwwlogs/gdmizi.com.log;
 error_log /home/wwwlogs/gdmizi.com.error.log;
}

以上配置可将www.gdmizi.com、gdmizi.com与https://gdmizi.com 重定向至https://www.gdmizi.com地扯中。

注意

记得将防火墙的80与443端口打开。

 

相关链接:

http://blog.csdn.net/dounine/article/details/53734631

https://www.cnblogs.com/brucetang/p/6145072.html

https://segmentfault.com/q/1010000006994159

https://www.cnblogs.com/yun007/p/3739182.html

https://www.cnblogs.com/kevingrace/p/6187072.html

点赞

发表评论

电子邮件地址不会被公开。 必填项已用*标注