服务器配置https加密访问

本文讲述两中配置方式,使用tomcat作为项目的部署服务器

第一种方式同构nginx方式进行代理

编辑nginx的nginx.conf配置文件
第一步配置证书
 server {
	listen 443 ssl;
	server_name cswlbc.cn;  # localhost修改为您证书绑定的域名。
	#ssl on;   #设置为on启用SSL功能。 在nginx 1.2 版本这样配置,以上需要配置成listen 443 ssl;
	root html;
	index index.html index.htm;
	ssl_certificate  C:\cert\1728050_cswlbc.cn.pem;   #将domain name.pem替换成您证书的文件名。
	ssl_certificate_key C:\cert\1728050_cswlbc.cn.key;   #将domain name.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;   
	location / {
	proxy_pass http://127.0.0.1:8080/mochen/test.jsp; #反向代理跳转地址
	        proxy_set_header Host $http_host;
	        proxy_set_header X-Real-IP $remote_addr;  
	        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;  
	        proxy_set_header X-Forwarded-Proto $scheme;
	}
}

第二步配置http请求强行转到https
server {
    listen 80;
    server_name cswlbc.cn;  #使用您证书绑定的域名替换localhost。
    return  https://$server_name$request_uri;
}
第三步配置修改tomcat server.xml 文件

第一处

<Connector port="8080" protocol="HTTP/1.1"
            connectionTimeout="20000"
         redirectPort="8443"/>
修改为
<Connector port="8080" protocol="HTTP/1.1"
            connectionTimeout="20000"
         redirectPort="443" proxyPort="443"/>
 

第二处
在标签中加入

<Valve className="org.apache.catalina.valves.RemoteIpValve"remoteIpHeader="X-Forwarded-For"
protocolHeader="X-Forwarded-Proto"
protocolHeaderHttpsValue="https" />

nginx 常用指令:

nginx -s reload 重新加载
nginx -s stop 停止

第二种方式通过tomcat方式进行加密

在tomcat的server.xml文件中如下修改

第一步

<Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" URIEncoding="UTF-8" useBodyEncodingForURI="true"/>
 
修改为
             <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="443" URIEncoding="UTF-8" useBodyEncodingForURI="true"/>

第二步
加入以下配置

<Connector port="443" protocol="org.apache.coyote.http11.Http11NioProtocol"
               maxThreads="150" SSLEnabled="true"  scheme="https"
    secure="true"
               >
        <SSLHostConfig>
             <Certificate certificateKeystoreFile="C:\cert\1728050_cswlbc.cn.pfx"
                         certificateKeystoreType="PKCS12" certificateKeystorePassword="3E9nnjT5" />
        </SSLHostConfig>
</Connector>

第三步

<Connector port="8009" protocol="AJP/1.3" redirectPort="8443"/>
修改为
<Connector port="8009" protocol="AJP/1.3" redirectPort="443"/>

第四步
在web.xml文件中标签上一行加入

<login-config>
    <auth-method>CLIENT-CERT</auth-method>  
    <realm-name>Client Cert Users-only Area</realm-name>  
</login-config>  
<security-constraint>  
    <web-resource-collection >  
        <web-resource-name >SSL</web-resource-name>  
        <url-pattern>/*</url-pattern>  
    </web-resource-collection>  
    <user-data-constraint>  
        <transport-guarantee>CONFIDENTIAL</transport-guarantee>  
    </user-data-constraint>  
</security-constraint>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值