Configure Nginx + HTTPS + Tomcat/nginx + HTTPS + Jar/nginx + HTTPS + Tomcat + War

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.