Jetty:设置通用主机 [英] Jetty: set up general host
问题描述
如何强制 Jetty 从特定虚拟主机(如 test.localhost:8080/myapp
而非 localhost:8181/myapp
)开始打开所有已部署的 web 应用程序?>
这是来自 jetty.xml 的片段:
<Arg><New class="org.eclipse.jetty.server.nio.SelectChannelConnector"><设置名称=主机"><属性名称="jetty.host"/></设置><设置名称="端口"><属性名称=jetty.port"默认=8181"/></设置>...
...我尝试使用 jetty.host
值但仍然没有成功.:(
怎么做?
要侦听特定网络接口,您可以通过其 IP 地址(IPv4 或 IPv6)或其主机名指定该接口.
由于这是本地主机/环回的变体,因此最好使用 IP 地址.
例如:
$ grep localhost/etc/hosts127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4::1 localhost localhost.localdomain localhost6 localhost6.localdomain6127.0.1.0 测试.本地主机
是的,这些主机故意使用不同的 IP(并且对环回接口有效).
然后,您可以使用 jetty-distribution 为 test.localhost:8080
设置连接器,使用命令行(这是 jetty 9 语法)
$ java -jar/path/to/start.jar jetty.host=127.0.1.0 jetty.port=8080
您也可以将这些命令行选项作为单独的行放入 ${jetty.base}/start.ini
.
$ grep -E "jetty\.(host|port)"/path/to/my.base/start.inijetty.host=127.0.1.0码头.port=8080
jetty启动后,可以看到正在监听的界面
$ netstat -tlnp |8080(并非所有进程都可以识别,非拥有的进程信息不会显示,你必须是 root 才能看到这一切.)tcp4 0 0 127.0.1.0:8080 :::* 听 14480/java
How can i force Jetty to open all deployed webapps starting from specific virtual host like test.localhost:8080/myapp
instead of localhost:8181/myapp
?
Here's snippet from jetty.xml:
<Call name="addConnector">
<Arg>
<New class="org.eclipse.jetty.server.nio.SelectChannelConnector">
<Set name="host">
<Property name="jetty.host"/>
</Set>
<Set name="port">
<Property name="jetty.port" default="8181"/>
</Set>
...
... i tried to play with jetty.host
value but still no success. :(
How to?
To LISTEN on a specific network interface, you specify that interface either via its IP address (IPv4 or IPv6) or its hostname.
Since this is a variant of localhost / loopback, then using IP address would be best.
Eg:
$ grep localhost /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
127.0.1.0 test.localhost
Yes, those hosts are on different IPs, intentionally (and valid for the loopback interface).
You could then setup the connector, using the jetty-distribution, for test.localhost:8080
by using the command line (this is jetty 9 syntax)
$ java -jar /path/to/start.jar jetty.host=127.0.1.0 jetty.port=8080
You can also put those command line options into your ${jetty.base}/start.ini
as separate lines.
$ grep -E "jetty\.(host|port)" /path/to/my.base/start.ini
jetty.host=127.0.1.0
jetty.port=8080
Once jetty is started, you can see what interface it is listening on
$ netstat -tlnp | grep 8080
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp4 0 0 127.0.1.0:8080 :::* LISTEN 14480/java
这篇关于Jetty:设置通用主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!