关于nginx+tomcat https的部署之前网上一直有2种说法:
1.nginx和tomcat都要部署ssl证书
2.nginx部署ssl证书,tomcat增加ssl支持
我个人觉得 nginx+nginx中部署ssl证书+tomcat 的部署比较方便,以下是具体步骤:
第一步:
tomcat 中的设置,找到 tomcat7x/conf/server.xml 文件多加这两个
scheme=“https” proxyPort=“443” 还有 URIEncoding=“UTF-8” 是编码用的
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
scheme="https"
proxyPort="443"
redirectPort="8443" />
<Connector port="8010" protocol="AJP/1.3" redirectPort="8443" URIEncoding="UTF-8" />
还有在Engine 里加以下的配置:
<Valve className="org.apache.catalina.valves.RemoteIpValve"
remoteIpHeader="X-Forwarded-For"
protocolHeader="X-Forwarded-Proto"
protocolHeaderHttpsValue="https"/>
第二步:
nginx中的配置:
server {
listen 443;
server_name www.mydemo .cn; #mydemo 你的域名
ssl on;
root html;
index index.html index.htm;
ssl_certificate cert/a.pem;
ssl_certificate_key cert/a.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 / {
root /www/server/tomcat7x/webapps/mydemo/;
index index.html index.htm;
proxy_pass http://www.mydemo.cn:8080; #mydemo 你的域名
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_redirect off;
proxy_connect_timeout 240;
proxy_send_timeout 240;
proxy_read_timeout 240;
proxy_set_header X-Forwarded-Proto $scheme; #对应tomcat 中的,一定要配置不然会出错
}
access_log /www/wwwlogs/access.log;
}
我配置的时候遇到很多坑,所记录下,希望可以帮助到你们,如果还什么疑问可以,留言一起讨论