nginx https反向代理tomcat的2種實(shí)現(xiàn)方法
反向代理
在計(jì)算機(jī)世界里,由于單個(gè)服務(wù)器的處理客戶端(用戶)請(qǐng)求能力有一個(gè)極限,當(dāng)用戶的接入請(qǐng)求蜂擁而入時(shí),會(huì)造成服務(wù)器忙不過來的局面,可以使用多個(gè)服務(wù)器來共同分擔(dān)成千上萬的用戶請(qǐng)求,這些服務(wù)器提供相同的服務(wù),對(duì)于用戶來說,根本感覺不到任何差別。
nginx做前端代理分發(fā),tomcat處理請(qǐng)求。nginx反代tomcat實(shí)現(xiàn)https有二個(gè)方法。
一、nginx配置https,tomcat也配置https
1、nginx配置https
upstream https_tomcat_web { server 127.0.0.1:8443; } server { listen 443; server_name www.test.com; index index.html; root /var/www/html/test; ssl on; ssl_certificate /etc/nginx/go.pem; ssl_certificate_key /etc/nginx/go.key; ssl_session_timeout 5m; ssl_protocols SSLv2 SSLv3 TLSv1.2; # ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; ssl_prefer_server_ciphers on; location ~ ^/admin { proxy_pass https://https_tomcat_web; //是https的 proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; client_max_body_size 100m; client_body_buffer_size 256k; proxy_connect_timeout 60; proxy_send_timeout 30; proxy_read_timeout 30; proxy_buffer_size 8k; proxy_buffers 8 64k; proxy_busy_buffers_size 64k; proxy_temp_file_write_size 64k; } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } }
2、tomcat的https配置,配置文件server.xml
<Service name="Catalina"> <Connector port="8001" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" /> <Connector port="8091" protocol="AJP/1.3" redirectPort="8443" /> //添加以下內(nèi)容 <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true" scheme="https" secure="false" keystoreFile="cert/gotom.pfx" keystoreType="PKCS12" keystorePass="214261272770418" clientAuth="false" SSLProtocol="TLSv1+TLSv1.1+TLSv1.2" ciphers="TLS_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_256_CBC_SHA,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,TLS_RSA_WITH_AES_128_CBC_SHA256,TLS_RSA_WITH_AES_256_CBC_SHA256" /> ..................省略.................... </Service>
配置好后重新啟動(dòng)nginx,tomcat,就可以https訪問了,這也是我現(xiàn)在采用的配置方式 。
二、nginx采用https,tomcat采用http
1、nginx配置https
upstream https_tomcat_web { server 127.0.0.1:8001; } server { listen 443; server_name www.test.com; index index.html; root /var/www/html/test; ssl on; ssl_certificate /etc/nginx/go.pem; ssl_certificate_key /etc/nginx/go.key; ssl_session_timeout 5m; ssl_protocols SSLv2 SSLv3 TLSv1.2; # ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; ssl_prefer_server_ciphers on; location ~ ^/admin { proxy_pass http://https_tomcat_web; //是http的 proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; client_max_body_size 100m; client_body_buffer_size 256k; proxy_connect_timeout 60; proxy_send_timeout 30; proxy_read_timeout 30; proxy_buffer_size 8k; proxy_buffers 8 64k; proxy_busy_buffers_size 64k; proxy_temp_file_write_size 64k; } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } }
2、tomcat的http配置,配置文件server.xml
<Service name="Catalina"> <Connector port="8001" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="443" /> //在這里重新定向到了443端口 <Connector port="8091" protocol="AJP/1.3" redirectPort="443" /> ..................省略.................... </Service>
重啟nginx,tomcat,https就配置好了。
不管是第一種方法,還是第二種方法,如果通過http,直接訪問8001端口,瀏覽器都會(huì)提示你不安全的訪問,因?yàn)楸旧硎莌ttp,確被重定向到了https。
總結(jié)
以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,如果有疑問大家可以留言交流,謝謝大家對(duì)腳本之家的支持。
- Nginx+Tomcat反向代理與負(fù)載均衡的實(shí)現(xiàn)
- Nginx反向代理轉(zhuǎn)發(fā)tomcat的實(shí)現(xiàn)
- Tomcat獲取Nginx反向代理的客戶端域名
- 詳解Linux中Nginx反向代理下的tomcat集群
- 詳解Nginx反向代理到Tomcat服務(wù)器
- 詳解Nginx + Tomcat 反向代理 負(fù)載均衡 集群 部署指南
- 簡(jiǎn)單實(shí)現(xiàn)nginx+tomcat的反向代理與動(dòng)靜分離
- Nginx為Tomcat服務(wù)器作反向代理的配置教程
- nginx+tomcat實(shí)現(xiàn)多級(jí)反向代理的示例代碼
相關(guān)文章
使用nginx+tomcat+keepalived實(shí)現(xiàn)高可用的詳細(xì)步驟
這篇文章主要介紹了nginx+tomcat+keepalived實(shí)現(xiàn)高可用,包括安裝nginx服務(wù)的步驟,詳細(xì)介紹了安裝keepalived的方法,對(duì)nginx+tomcat+keepalived高可用相關(guān)知識(shí)感興趣的朋友一起看看吧2022-03-03nginx反向代理服務(wù)因配置文件錯(cuò)誤導(dǎo)致訪問資源時(shí)出現(xiàn)404
這篇文章主要介紹了nginx反向代理服務(wù)因配置文件錯(cuò)誤導(dǎo)致訪問資源時(shí)出現(xiàn)404,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-06-06詳解Nginx服務(wù)器中配置超時(shí)時(shí)間的方法
這篇文章主要介紹了Nginx服務(wù)器中配置超時(shí)時(shí)間的方法,同時(shí)也對(duì)Nginx中的時(shí)間管理機(jī)制作了詳細(xì)的介紹,需要的朋友可以參考下2015-12-12Nginx中404頁面的配置及AJAX請(qǐng)求返回404頁面的方法
404是請(qǐng)求頁面不存在的錯(cuò)誤代碼,在Nginx中有時(shí)處理jQuery中的ajax方法雖然能返回404頁面但錯(cuò)誤代碼卻返回200,針對(duì)此問題我們具體來看一下Nginx中404頁面的配置及AJAX請(qǐng)求返回404頁面的方法2016-05-05