Nginx配置80端口訪問8080及項(xiàng)目名地址方法解析
tomcat訪問項(xiàng)目,一般是 ip + 端口 + 項(xiàng)目名
nginx 配置 location / {} ,一般只能跳轉(zhuǎn)到 ip + 端口,如果想要直接訪問項(xiàng)目,就需要修改tomcat的配置了
如何保證不修改tomcat的配置,只修改nginx,可以訪問端口+項(xiàng)目名
在嘗試后發(fā)現(xiàn)一種方法,就是通過
location / {
proxy_pass http://127.0.0.1:8080/demo;
}
跳轉(zhuǎn)到
location /demo {
proxy_pass http://127.0.0.1:8080;
}
demo 是項(xiàng)目名,就是配置在tomcat的webapps下的文件名
只是這樣的配置,會(huì)在url地址中 顯示出項(xiàng)目名,但有什么所謂呢
下面是一個(gè)配置示例:
upstream tomcatproject{ ip_hash; server 11.1.11.11:8080; server 22.2.22.22:8080; } server { listen 80; #server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { 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; proxy_pass http://tomcatproject/demo; } location /demo/ { 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; proxy_pass http://tomcatproject; } }
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持本站。
版權(quán)聲明:本站文章來源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請(qǐng)保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學(xué)習(xí)參考,不代表本站立場,如有內(nèi)容涉嫌侵權(quán),請(qǐng)聯(lián)系alex-e#qq.com處理。