1.1 准备阶段
1、 程序代码http和https协议跳转编写完成
2、 使用resin、tomcat能够正常启动
3、 安装nginx
4、 修改nginx配置文件
1.2 程序代码http和https协议跳转说明
我们以前通常使用JavaScript的window.location、$(this).attr(“href”,”地址”)方法作为页面跳转。通常情况下,以上的那些跳转的那方法是可以实现的,但是,如果使用以上的方法转跳到https协议是不可取的。
那么现在如何从http跳转到https协议,我的方法是使用window.location这个方法进行转跳的,书写方式为:window.location=https://IP:端口/地址。
同样的,从https跳转到http也是同样的方法,书写方式为:window.location=http://IP:端口/地址
1.3 修改nginx配置文件
查找nginx的安装部署
附conf/servers文件夹下的配置说明 upstream backendServer{
ip_hash;
#此IP和端口是用tomcat或resin启动后的IP和端口
server 127.0.0.1:8070;
}
#这是一个https的server
server{
#设置监听端口,https访问端口
listen 443 default;
#设置服务器域名(IP访问和多域名访问可不设置)
#server_name _*;
server_name www.test.com;
#开启shtml支持
ssi on;
ssi_silent_errors on;
ssi_types text/shtml;
#开启SSL支持
ssl on;
#下面两个为导入证书,可根据自己实际情况更改,我的这两个文件是放在conf文件下
ssl_certificate server.pem;
ssl_certificate_key server.key;
ssl_session_timeout 5m;
ssl_protocols SSLv3 TLSv1;
#ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:!SSLv2:+EXP;
#ssl_prefer_server_ciphers on;
#设置主访问日志
#access_log logs/access.log main;
access_log /dev/null;
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
#说明location,假设有个一个URL地址为:http://127.0.0.1:8070/plan,经过nginx代理后,https的访问地址为:https://127.0.0.1:443/plan。
#location小括号(userSpace|cloudinvest|servlet|plan|aboutcapital)里面的值即为URL地址的路径,表示在userSpace,cloudinvest,setvlet,plan,aboutcapital路径下都为https的协议。若一个URL地址为:http://127.0.0.1:8070/ques。用户https协议访问将会报404错误。
location ~ (^/(userSpace|cloudinvest|servlet|plan|aboutcapital)/|\.js|\.css|\.png|\.jpg|\.gif){
proxy_pass http://127.0.0.1:8070;
include proxy.conf;
}
#设置监控nginx状态URL
location /__nginxstatus
{
stub_status on;
access_log off;
}
}
1.4 测试
完成以上步骤后,可以直接测试
例:
http://IP:端口/ques
https://IP:443/plan
|