Nginx-Nginx + Tomcat 端口修改后访问不了

发布于 2016-11-09 19:30:34 字数 6334 浏览 1345 评论 1

现有两台服务器,IP分别为IP1和IP2,部署如下:
服务器1:Nginx + Tomcat
服务器2:Tomcat
Nginx配置文件为:

worker_processes 2;
events {
worker_connections 8096;
}
http {
include mime.types;
default_type application/octet-stream;
load_iwall D:\nginx-1.5.4\nginx-1.5.4\libiwx.dll C:\Tercel\iWall2\;
enable_iwall on;
sendfile on;
keepalive_timeout 65;
upstream IP1{
ip_hash;
server IP1:8080;
server IP2:8080;
}
server {
listen IP1:80;
server_name IP1;
location / {
root html;
index index.html index.jsp;
proxy_pass http://IP1;
}
}
}

服务器1和服务器2Tomcat配置文件相同,配置文件如下:

<?xml version="1.0" encoding="UTF-8"?>
<Server port="8005" shutdown="SHUTDOWNNall">

<!--APR library loader. Documentation at /docs/apr.html -->
<Listener SSLEngine="on" className="org.apache.catalina.core.AprLifecycleListener"/>
<!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->
<Listener className="org.apache.catalina.core.JasperListener"/>
<!-- Prevent memory leaks due to use of particular java/javax APIs-->
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener"/>
<!-- JMX Support for the Tomcat server. Documentation at /docs/non-existent.html -->
<Listener className="org.apache.catalina.mbeans.ServerLifecycleListener"/>
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>

<!-- 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 auth="Container" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" name="UserDatabase" pathname="conf/tomcat-users.xml" type="org.apache.catalina.UserDatabase"/>
</GlobalNamingResources>

<!-- A "Service" is a collection of one or more "Connectors" that share
a single "Container" Note: A "Service" is not itself a "Container",
so you may not define subcomponents such as "Valves" at this level.
Documentation at /docs/config/service.html
-->
<Service name="Catalina">

<!--The connectors can use a shared executor, you can define one or more named thread pools-->
<!--
<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
maxThreads="150" minSpareThreads="4"/>
-->

<Connector className="org.apache.catalina.http.HttpConnector" port="8443" minProcessors="5"
maxprocessors="100" enableLookups="true" acceptCount="10" debug="0" scheme="https" secure="true"/>
<Factory classname="org.apache.catalina.SSLServerSocketFactory" clientAuth="false" keystoreFile="/path/to/my/keystore" keystorePass="runway"
protocl="TLS"/>
<!-- A "Connector" represents an endpoint by which requests are received
and responses are returned. Documentation at :
Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
Java AJP Connector: /docs/config/ajp.html
APR (HTTP/AJP) Connector: /docs/apr.html
Define a non-SSL HTTP/1.1 Connector on port 8080 -->
<Connector URIEncoding="UTF-8" connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>
<!-- A "Connector" using the shared thread pool-->
<!--
<Connector executor="tomcatThreadPool"
port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" URIEncoding="UTF-8" />
-->
<!-- Define a SSL HTTP/1.1 Connector on port 8443
This connector uses the JSSE configuration, when using APR, the
connector should be using the OpenSSL style configuration
described in the APR documentation -->
<!--
<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
maxThreads="150" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS" />
-->


<Connector URIEncoding="UTF-8" port="8009" protocol="AJP/1.3" redirectPort="8443"/>

<Engine defaultHost="localhost" name="Catalina">


<Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>

<!-- Define the default virtual host
Note: XML Schema validation will not work with Xerces 2.2.
-->
<Host appBase="webapps" autoDeploy="true" deployXML="false" name="localhost" unpackWARs="true" xmlNamespaceAware="false" xmlValidation="false">

<!-- SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
-->

<!-- Access log processes all example.
Documentation at: /docs/config/valve.html -->

<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/>

</Host>
</Engine>
</Service>
</Server>

此时,用户通过http://IP1/zh可以正常访问,接下来,把Nginx和Tomcat配置文件的8080全改为9090,其他不变,重启Tomcat和Nginx,通过http://IP1:9090/zh可以访问,但是用http://IP1/zh访问时报网关超时,8080端口和9090端口的访问权限是一致的。
请知道的朋友帮帮忙,急等,谢谢!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浮生未歇 2017-03-08 17:58:14

问题找到了,犯了个低级错误,现在说出来希望大家也引以为鉴:由于之前已有同事重启过几次nginx,有的同事重启前没有先停服务,这样每次重启就多了一个nginx进程,而我执行停止服务命令时只是关闭了其中的一个进程,表面上是服务停止了,实际上还有进程在占用配置文件,所以没有把更新后的配置信息写进去,方式就是找到所有的nginx进程关闭,然后再重启。

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文