英文:
Run Tomcat on *:<port> instead of localhost:<port>
问题
我正在尝试从Parallels Desktop访问我的本地主机服务器,但遇到了一些问题。
例如,我有一个在Spring Boot上运行的应用,它在端口8081上运行,我在终端中运行sudo lsof -PiTCP -sTCP:LISTEN命令,得到以下输出:
java      8168 username  107u  IPv6 0x53524f3d71f26ae5      0t0  TCP *:8081 (LISTEN)
而第二个应用程序(不是Spring Boot,而是在Tomcat 7中的Spring应用程序)的输出是:
java      7756 username  504u  IPv6 0x53524f3d6cfe6fa5      0t0  TCP localhost:8096 (LISTEN)
我可以通过地址http://10.211.55.2:8081/轻松访问第一个应用程序,但对于http://10.211.55.2:8096/,我收到“无法访问此站点”的错误消息。
那么,我如何将我的第二个应用程序从localhost:8096更改为*:8096上运行呢?
英文:
I am trying to access my localhost server from Parallels Desktop and facing some issues.
For example, I have an app on Spring Boot that runs on port 8081, and running sudo lsof -PiTCP -sTCP:LISTEN in Terminal gives me the following output:
java      8168 username  107u  IPv6 0x53524f3d71f26ae5      0t0  TCP *:8081 (LISTEN)
And the output for second application (not Spring Boot, but Spring inside Tomcat 7) is:
java      7756 username  504u  IPv6 0x53524f3d6cfe6fa5      0t0  TCP localhost:8096 (LISTEN)
I can easily access the first application from Parallels Desktop by address http://10.211.55.2:8081/, but doing the same for http://10.211.55.2:8096/ gives me this site can’t be reached error message.
So, how can I run my second application on *:8096 instead of localhost:8096?
答案1
得分: 1
IP地址是Tomcat监听的,由Tomcat配置文件server.xml中连接器元素中的address属性 控制。
要监听所有地址,请将地址设置为 0.0.0.0:
<Connector port="8096"
           address="0.0.0.0"
           ...其他属性.../>
英文:
The IP address tomcat listens in is controlled by the address attribute in the connector element in tomcat configuration file server.xml.
To listen on all addresses, set the address to 0.0.0.0:
<Connector port="8096" 
           address="0.0.0.0"
           ...other attributes.../>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论