Nginx实现http转https需要把80端口重定向到443端口,有以下几种: 1、rewrite重写地址 2、porxy_pass 3、等 笔者利用http的html中使用refresh标签实现跳转。
//原网页server配置
server {
listen 80;
server_name coderr.cn www.coderr.cn;
#charset koi8-r;
access_log /var/log/nginx/http.coderr.cn.log main;
location / {
//重写方法实现301永久重定向跳转,本文使用html跳转
#rewrite ^(.*) https://coderr.cn permanent;
root /var/www/html/test;
//原网页身份认证模块
#auth_basic "coderr.cn";
#auth_basic_user_file /mnt/htpasswd;
index index.html index.htm;
}
。。。。。。
}
/*
For Nginx it is required to have all the certificates (one for your domain name and CA ones) combined in a single file. The certificate for your domain should be listed first in the file, followed by the chain of CA certificates.
To combine the certificates in case of PositiveSSL, run the following command in terminal:
$ cat *yourdomainname*.crt ComodoRSADomainValidationSecureServerCA.crt COMODORSAAddTrustCA.crt AddTrustExternalCARoot.crt >> cert_chain.crt
Note! If you have downloaded a complete CABundle file for your certificate, replace chain files' names with the name of your downloaded file. It will look like:
$ cat *yourdomainname*.crt COMODO_DV_SHA-256_bundle.crt >> cert_chain.crt
or
$ cat *yourdomainname*.crt *yourdomainname*.ca-bundle >> cert_chain.crt
*/
//ssl模块配置
server {
listen 443 ;
server_name www.coderr.cn coderr.cn;
access_log /var/log/nginx/https.coderr.cn.log main;
location /{
#proxy_pass http://weibo.com/u/3251610014;
root /var/www/html;
index index.html index.htm;
}
ssl on;
#ssl_certificate /var/www/html/ssl/certificate.crt;
ssl_certificate /var/www/html/ssl/cert_chain.crt;
ssl_certificate_key /var/www/html/ssl/private.key;
}
//html跳转代码
<html>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<meta http-equiv = "refresh" content = "0;url=http://blog.csdn.net/sinat_29173167">
<head><title>coderr.cn</title></head>
</html>
#用httpd-tools配置auth
location / {
auth_basic "coderr.cn";
auth_basic_user_file /mnt/htpasswd;
index index.php;
}
location /log {
alias /var/log/nginx;
# alias /tmp/download;
auth_basic "coderr.cn";
auth_basic_user_file /mnt/htpasswd;
autoindex on;
}
备份地址: 【Nginx实现http转https】