nginx 强制使用https访问(http跳转到https)
2015-05-21 17:09
956 查看
nginx强制使用https访问(http跳转到https)
基于nginx搭建了一个https访问的虚拟主机,监听的域名是test.com,但是很多用户不清楚https和http的区别,会很容易敲成http://test.com,这时会报出404错误,所以我需要做基于test.com域名的http向https的强制跳转。1.[b]生成RSA密钥的方法[/b]
openssl genrsa -des3 -out privkey.pem 2048 |
openssl genrsa -out privkey.pem 2048 |
建议用2048位密钥,少于此可能会不安全或很快将不安全:
openssl req -new -key privkey.pem -out cert.csr |
这里将生成一个新的文件cert.csr,即一个证书请求文件,你可以拿着这个文件去数字证书颁发机构(即CA)申请一个数字证书。CA会给你一个新的文件cacert.pem,那才是你的数字证书。
如果是自己做测试,那么证书的申请机构和颁发机构都是自己。就可以用下面这个命令来生成证书:
openssl req -new -x509 -key privkey.pem -out cacert.pem -days 1095 |
以上原文:http://blog.csdn.net/lgm252008/article/details/5402250
利用nginx的497状态码跳转到https
当此虚拟站点只允许https访问时,当用http访问时nginx会报出497错误码;利用error_page命令将497状态码的链接重定向到https://test.com这个域名上;
server { listen 443; #ssl端口 listen 80; #用户习惯用http访问,加上80,后面通过497状态码让它自动跳到443 server_name test.com; ssl on; #为一个server{......}开启ssl支持 ssl_certificate /etc/nginx/test.pem; #指定PEM格式的证书文件 ssl_certificate_key /etc/nginx/test.key; #指定PEM格式的私钥文件 error_page 497 https://$host$uri?$args; #让http请求重定向到https请求 } |
第二种方法:利用 index.html网页进行跳转
在nginx的配置文件中,新增加一个虚拟机,端口为80;
server { listen 80; server_name test.com; location / { root /data/nginx/; #index.html放在虚拟主机监听的根目录下 } error_page 404 https://test.com/; #将404的页面重定向到https的首页 } |
<html> <meta http-equiv="refresh" content="0;url=https://test.com/"> </html> |
以上原文:/article/6222377.html
相关文章推荐
- nginx强制使用https访问(http跳转到https)
- nginx强制使用https访问(http跳转到https)
- nginx强制使用https访问(http跳转到https)
- nginx强制使用https访问(http跳转到https)
- nginx强制使用https访问(http跳转到https)
- nginx强制使用https访问(http跳转到https)
- 【环境配置】申请StartSSL免费CA证书,配置Nginx使用https访问,强制http跳转到https
- nginx强制使用https访问(http跳转到https)
- nginx强制使用https访问(http跳转到https
- Nginx强制使用https访问(http跳转到https)
- Nginx强制使用https访问(http跳转到https)
- nginx强制使用https访问(http跳转到https)
- nginx强制使用https访问(http跳转到https)
- nginx强制使用https访问(http跳转到https)
- nginx强制使用https访问的方法(http跳转到https)
- nginx强制使用https访问(http跳转到https)
- nginx强制使用https访问 http跳转到https
- nginx强制使用https访问(http跳转到https)
- nginx强制使用https访问(http跳转到https) mark
- 使用nginx实现http访问自动跳转到https端口