http强制跳转到https

发布时间:2014-03-29 03:01:32 阅读:1299次

转:http://blog.nicky1605.com/the-http-mandatory-jump-to-https.html 

之前我说了设置如何添加https,因为https比http要安全一点,所以我想让所有从http访问我的网站的人强制跳转到https,这就需要添加以下:

1
server {

listen 80;

server_name my.nicky1605.com;

#rewrite ^/(.*) permanent;    #记得修改成你的网站

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

也就是再添加一个虚拟机,80端口一个,443端口一个server。

但是有些程序只会给你往端口上转发,不会自动修正http为https,这样的程序还不少,例如phpmyadmin:

遇到这样的程序我们需要修改Nginx.conf配置文件,在443的server的fastcgi字段中添加一个语句:

1
fastcgi_param HTTPS on;#attention!#

例如

1
2
3
4
5
6
7
8
         location ~ .*\.(php|php5)?$
            {
                try_files $uri =404;
                fastcgi_pass  unix:/tmp/php-cgi.sock;
                fastcgi_index index.php;
                fastcgi_param HTTPS on;#attention!#
                include fcgi.conf;
            }

 这样就可以了。

转:http://zhumeng8337797.blog.163.com/blog/static/100768914201072051336303/首先安装SSL,再编译安装APACHE,再配置证书即可
1. 下载安装apache和openssl
网址:http://www.apache.org,http://www.openssl.org
#tar zxvf httpd-2.0.54.tar.gz
#tar zxvf openssl-0.9.7g.tar.gz
编译安装openssl,这个软件主要是用来生成证书
#cd openssl-0.9.7g
#./config
#make
#make test
#make install
把 openssl放进内核目录下,使其在任何目录下都能运行。
#cd /usr/local/bin
#ln -s /usr/local/ssl/bin/openssl openssl
编译安装apache
#cd /opt/httpd-2.0.54
#./configure --prefix="/opt/apache2" --enable-so --enable-ssl --with-ssl="/usr/local/ssl/bin"
#make
#make install
2. 安装完毕,生成证书:
在/opt/apache2/conf下建立一个ssl.key目录
#cd ../apache2/
#cd conf/
#mkdir ssl.key
然后在该目录下生成证书:
#cd ssl.key/
生成服务器私钥:
#openssl genrsa -des3 -out server.key 1024
Generating RSA private key, 1024 bit long modulus
.......................++++++
.................................................++++++
e is 65537 (0x10001)
Enter pass phrase for server.key: //密码
Verifying - Enter pass phrase for server.key: //确认和上面密码相同
生成服务器证书请求,并按要求填些相关证书信息:
#openssl req -new -key server.key -out server.csr
Enter pass phrase for server.key: //上面的密码
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:CN
State or Province Name (full name) [Some-State]:BJ
Locality Name (eg, city) []:BJ
Organization Name (eg, company) [Internet Widgits Pty Ltd]:163
Organizational Unit Name (eg, section) []:TD
Common Name (eg, YOUR name) []:a.test.com//行使 SSL 加密的网站地址。请注意这里并不是单指您的域名,而是直接使用 SSL 的网站名称 例如:pay.abc.com。 一个网站这里的定是:abc.com是一个网站;www.abc.com 是另外一个网站;pay.abc.com 又是另外一个网站。
Email Address []:lala@corp.netease.com
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:**********
An optional company name []:126
签证:
# openssl x509 -req -days 700 -in server.csr -signkey server.key -out server.crt
Signature ok
subject=/C=AU/ST=Some-State/L=tyl/O=tz/OU=tz/CN=tyl/emailAddress=tangyl@ruyi.com
Getting Private key
Enter pass phrase for server.key: //输入创建key时的密码
3. 修改httpd.conf文件
Apache一般有2个版本下载,一个是带SSL模块的,一个是不带SSL的,请首先检查自己的SSL是包含了SSL模块的,否则就没法做了。 Apache的参数配置都在httpd.conf文件中,SSL配置也是如此,此外还可以通过include httpd-ssl.conf来包含一个专门配置SSL的配置文件,如果激活了httpd-include ssl.conf,则可以打开httpd-ssl.conf来配置相应参数。
一般,我们直接在httpd.conf文件中直接配置SSL参数:
#加载模块mod_ssl.so,此模块是启

如有问题,可以QQ搜索群1028468525加入群聊,欢迎一起研究技术

支付宝 微信

有疑问联系站长,请联系QQ:QQ咨询
上一篇:http与https并存

转载请注明:http强制跳转到https 出自老鄢博客 | 欢迎分享