1.nginx + HTTPS + Tomcat
Nginx Configuration:
server {
Listen 443;
server_name www.example.com; #域名
SSL on;
#index index.html index.htm;
Ssl_certificate Cert/1523584742511.pem; #证书
Ssl_certificate_key Cert/1523584732510.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 "C:/Program Files/apache-tomcat-8.5.30/webapps"; #tomcat路径
Index index.html index.htm;
}
}
server {
Listen 80;
server_name www.example.com; #域名
Rewrite ^ (. *) $ https://$host $ permanent; #将80端口的http转向443端口的https
}
2.nginx + HTTPS + jar
The spring boot packaged jar, which itself already contains built-in Tomcat, can run independently, so after the service is started anywhere
Now the Propertis in the Spring boot project adds the configuration:
Server.use-forward-headers=true
Server.tomcat.remote-ip-header=x-forwarded-for
Server.tomcat.protocol-header=x-forwarded-proto
Server.tomcat.port-header=x-forwarded-port
Nginx Configuration:
server {
Listen 443;
server_name www.example.com;
SSL on;
#index index.html index.htm;
Ssl_certificate Cert/1523584742511.pem; #证书
Ssl_certificate_key Cert/1523234742510.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:9001/your-example-applet; #启动的jar服务名, that's the server.context-path= in the properties.
Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;
Proxy_set_header X-forwarded-proto $scheme;
Proxy_set_header x-forwarded-port $server _port;
}
}
server {
Listen 80;
server_name www.example.com;
Rewrite ^ (. *) $ https://$host $ permanent;
}
3.nginx + HTTPS + Tomcat + War
Exclude built-in Tomcat when fighting a war package
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<!--for war packs excluding tomcat--
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<!--used for runtime but excluding Tomcat when playing a war package
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
Nginx configuration is similar to:
server {
Listen 443;
server_name www.example.com;
SSL on;
#index index.html index.htm;
Ssl_certificate Cert/1523584742511.pem; #证书
Ssl_certificate_key Cert/1523583742510.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:9001/your-example-applet; #启动的jar服务名, that's the server.context-path= in the properties.
Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;
Proxy_set_header X-forwarded-proto $scheme;
Proxy_set_header x-forwarded-port $server _port;
Root "C:/Program Files/apache-tomcat-8.5.30/webapps"; #tomcat路径
Index index.html index.htm;
}
}
server {
Listen 80;
server_name www.example.com;
Rewrite ^ (. *) $ https://$host $ permanent;
}
Configure Nginx + HTTPS + Tomcat/nginx + HTTPS + Jar/nginx + HTTPS + Tomcat + War