午夜剧场伦理_日本一道高清_国产又黄又硬_91黄色网战_女同久久另类69精品国产_妹妹的朋友在线

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

java-web - Tomcat+Nginx實(shí)現(xiàn)動(dòng)靜分離的功能,動(dòng)態(tài)請(qǐng)求為什么沒(méi)有發(fā)到Tomcat這里?(已解決)

瀏覽:202日期:2023-08-18 17:44:21

問(wèn)題描述

問(wèn)題

RT因?yàn)樽罱雽W(xué)習(xí)一下Nginx服務(wù)器,就想搭建一個(gè)Tomcat+Nginx,簡(jiǎn)單的實(shí)現(xiàn)動(dòng)靜分離的功能。

具體代碼和配置版本

Ubuntu:ubuntu-16.04-desktop-amd64

JDK:jdk1.8.0_101

Tomcat:apache-tomcat-8.5.4

Nginx:nginx/1.10.0

ubuntu ip:192.168.182.129

Tomcat配置(/conf/server.xml)

<?xml version='1.0' encoding='UTF-8'?><!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the 'License'); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.--><!-- Note: A 'Server' is not itself a 'Container', so you may not define subcomponents such as 'Valves' at this level. Documentation at /docs/config/server.html --><Server port='8005' shutdown='SHUTDOWN'> <Listener className='org.apache.catalina.startup.VersionLoggerListener' /> <!-- Security listener. Documentation at /docs/config/listeners.html <Listener className='org.apache.catalina.security.SecurityListener' /> --> <!--APR library loader. Documentation at /docs/apr.html --> <Listener className='org.apache.catalina.core.AprLifecycleListener' SSLEngine='on' /> <!-- Prevent memory leaks due to use of particular java/javax APIs--> <Listener className='org.apache.catalina.core.JreMemoryLeakPreventionListener' /> <Listener className='org.apache.catalina.mbeans.GlobalResourcesLifecycleListener' /> <Listener className='org.apache.catalina.core.ThreadLocalLeakPreventionListener' /> <!-- Global JNDI resources Documentation at /docs/jndi-resources-howto.html --> <GlobalNamingResources> <!-- Editable user database that can also be used by UserDatabaseRealm to authenticate users --> <Resource name='UserDatabase' auth='Container' type='org.apache.catalina.UserDatabase' description='User database that can be updated and saved' factory='org.apache.catalina.users.MemoryUserDatabaseFactory' pathname='conf/tomcat-users.xml' /> </GlobalNamingResources> <Service name='Catalina'> <Connector port='8080' protocol='HTTP/1.1' connectionTimeout='20000' redirectPort='8443' /> <Connector port='8009' protocol='AJP/1.3' redirectPort='8443' /> <Engine name='Catalina' defaultHost='localhost'> <Realm className='org.apache.catalina.realm.LockOutRealm'><Realm className='org.apache.catalina.realm.UserDatabaseRealm' resourceName='UserDatabase'/> </Realm> <Host name='test.nt.springmvc.com' appBase='webapps/springmvc' unpackWARs='true' autoDeploy='true'><Context path='/springmvc' docBase='springmvc.war'/> <Valve className='org.apache.catalina.valves.AccessLogValve' directory='logs' prefix='localhost_access_log' suffix='.txt' pattern='%h %l %u %t &quot;%r&quot; %s %b' /> </Host> </Engine> </Service></Server>Nginx 配置(/nginx/sites-available/default)

upstream tomcat { server 192.168.182.129:8080; } server { listen 80 default_server; listen [::]:80 ; root /opt/apache-tomcat-8.5.4/webapps/springmvc; #server_name _; server_name test.nt.springmvc.com; location /{proxy_set_headerHost $host;proxy_set_headerX-Real-IP $remote_addr;proxy_set_headerX-Forwarded-For $proxy_add_x_forwarded_for;proxy_pass http://tomcat;try_files $uri $uri/ =404; }}測(cè)試

通過(guò)Tomcat,請(qǐng)求url:http://test.nt.springmvc.com:...

通過(guò)Nginx,請(qǐng)求url:http://test.nt.springmvc.com/

通過(guò)Nginx,請(qǐng)求url:http://test.nt.springmvc.com/...

通過(guò)Nginx,請(qǐng)求url:http://test.nt.springmvc.com/...

tomcat日志

192.168.182.129 - - [28/Jul/2016:15:11:36 +0800] 'GET /springmvc/test/ HTTP/1.1' 200 106192.168.182.129 - - [28/Jul/2016:15:12:40 +0800] 'GET / HTTP/1.0' 404 -192.168.182.129 - - [28/Jul/2016:15:13:05 +0800] 'GET /springmvc HTTP/1.0' 302 -192.168.182.129 - - [28/Jul/2016:15:13:05 +0800] 'GET /springmvc/ HTTP/1.0' 404 990Nginx日志

192.168.182.129 - - [28/Jul/2016:15:12:40 +0800] 'GET / HTTP/1.1' 404 0 '-' 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0'192.168.182.129 - - [28/Jul/2016:15:13:05 +0800] 'GET /springmvc HTTP/1.1' 302 5 '-' 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0'192.168.182.129 - - [28/Jul/2016:15:13:05 +0800] 'GET /springmvc/ HTTP/1.1' 404 441 '-' 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0'192.168.182.129 - - [28/Jul/2016:15:13:37 +0800] 'GET /springmvc/test HTTP/1.1' 404 152 '-' 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0'

通過(guò)日志可以看到,我第四次的請(qǐng)求并沒(méi)有轉(zhuǎn)發(fā)到Tomcat這里,找了網(wǎng)上好多文檔,都沒(méi)有發(fā)現(xiàn)是哪里出現(xiàn)的問(wèn)題。下面是對(duì)應(yīng)的網(wǎng)頁(yè)java-web - Tomcat+Nginx實(shí)現(xiàn)動(dòng)靜分離的功能,動(dòng)態(tài)請(qǐng)求為什么沒(méi)有發(fā)到Tomcat這里?(已解決)java-web - Tomcat+Nginx實(shí)現(xiàn)動(dòng)靜分離的功能,動(dòng)態(tài)請(qǐng)求為什么沒(méi)有發(fā)到Tomcat這里?(已解決)java-web - Tomcat+Nginx實(shí)現(xiàn)動(dòng)靜分離的功能,動(dòng)態(tài)請(qǐng)求為什么沒(méi)有發(fā)到Tomcat這里?(已解決)java-web - Tomcat+Nginx實(shí)現(xiàn)動(dòng)靜分離的功能,動(dòng)態(tài)請(qǐng)求為什么沒(méi)有發(fā)到Tomcat這里?(已解決)

解決方法Nginx 配置(/nginx/sites-available/default)

upstream tomcat { server 192.168.182.129:8080; } server { listen 80 default_server; listen [::]:80 ; root /opt/apache-tomcat-8.5.4/webapps/springmvc; server_name test.nt.springmvc.com; location / {proxy_set_headerHost $host;proxy_set_headerX-Real-IP $remote_addr;proxy_set_headerX-Forwarded-For $proxy_add_x_forwarded_for;proxy_pass http://tomcat;#try_files $uri $uri/ =404; }}

可以看到在nginx的配置文件中,將try_files $uri $uri/ =404注解掉就可以正常訪問(wèn)了

try_files

nginx上try_files 判斷文件是否存在

$uri

指的是請(qǐng)求的文件和路徑,不包括“?”或者“#”之后的東西$request_uri: /stat.php?id=1585378&web_id=1585378$uri /stat.php$document_uri: /stat.php

問(wèn)題解答

回答1:

upstream tomcat { server 192.168.182.129:8080; } server { listen 80 default_server; listen [::]:80 ; root /opt/apache-tomcat-8.5.4/webapps/springmvc; #**(這行拿掉)** #server_name _; server_name test.nt.springmvc.com; location /{ # location / { 斜杠后面加空格proxy_set_headerHost $host;proxy_set_headerX-Real-IP $remote_addr;proxy_set_headerX-Forwarded-For $proxy_add_x_forwarded_for;proxy_pass http://tomcat;try_files $uri $uri/ =404; }}

標(biāo)簽: java
主站蜘蛛池模板: 开心激情网五月天 | 久久国产中文字幕 | 国产成人精品av在线观 | 村上凉子av| 免费看的黄色网 | 果冻传媒少妇借种av剧情在线 | www.国产精品 | 草久久免费视频 | 日韩欧美视频在线播放 | 国产一区观看 | 日韩在线视频网 | 色综合天天操 | 高清视频一区二区三区 | 亚洲视频在线看 | 天堂网视频在线 | av影音先锋| 亚洲丁香网 | 免费一级黄色大片 | 美日韩中文字幕 | 亚洲国产精品欧美久久 | 这里只有精品999 | 在线观看日韩视频 | 日韩午夜视频在线观看 | 美日韩av在线| 天堂视频网| 在线看日韩av | 男人天堂新地址 | 日韩成人激情 | 69av在线| 精品国产一区二区三区在线观看 | 在线日韩视频 | 黄色一级视频在线观看 | 日日插日日操 | 黄色片一区二区 | www超碰在线| 欧美日韩精品在线观看 | 欧美日韩国产精品 | 波多野结衣视频一区二区 | 免费的av网址| 中文字幕欧美激情 | 黄色在线一区 |