【问题标题】:Jetty: Hide port number in the URLJetty:在 URL 中隐藏端口号
【发布时间】:2017-11-28 02:41:33
【问题描述】:

我买了一个域名:test.com

然后我通过以下方式运行码头:

/opt/jetty# nohup java -jar start.jar

当我访问我的网站 (http://test.com) 时,它不起作用,我需要添加端口号,例如:http://test.com:8080,这很脏。所以,我想删除或隐藏这个端口号。

我尝试使用以下端口号运行码头:

nohup java -jar start.jar -Djetty.http.port=8080

然后,在文件 jetty-http.xml(/opt/jetty/etc)中,我更改了行:

<Set name="port"><Property name="jetty.http.port" deprecated="jetty.port" default="8080" /></Set>

我正在使用:

  • Vaadin.
  • 马文。
  • 码头。

我应该在哪里管理这个?

编辑:

根据需要,这是 pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>test</artifactId>
    <packaging>war</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>test</name>

    <prerequisites>
        <maven>3</maven>
    </prerequisites>

    <properties>
        <vaadin.version>8.0.4</vaadin.version>
        <vaadin.plugin.version>8.0.4</vaadin.plugin.version>
        <jetty.plugin.version>9.3.9.v20160517</jetty.plugin.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <jetty.port>8080</jetty.port>
        <vaadin.widgetset.mode>local</vaadin.widgetset.mode>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.vaadin</groupId>
                <artifactId>vaadin-bom</artifactId>
                <version>${vaadin.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>com.vaadin</groupId>
            <artifactId>vaadin-compatibility-server</artifactId>
        </dependency>
        <dependency>
            <groupId>com.vaadin</groupId>
            <artifactId>vaadin-compatibility-client-compiled</artifactId>
        </dependency>
        <dependency>
            <groupId>com.vaadin</groupId>
            <artifactId>vaadin-server</artifactId>
        </dependency>
        <dependency>
            <groupId>com.vaadin</groupId>
            <artifactId>vaadin-client-compiled</artifactId>
        </dependency>
        <dependency>
            <groupId>com.vaadin</groupId>
            <artifactId>vaadin-themes</artifactId>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.0.1</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.0.0</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                    <packagingExcludes>WEB-INF/classes/VAADIN/widgetsets/WEB-INF/**</packagingExcludes>
                </configuration>
            </plugin>
            <plugin>
                <groupId>com.vaadin</groupId>
                <artifactId>vaadin-maven-plugin</artifactId>
                <version>${vaadin.plugin.version}</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>update-theme</goal>
                            <goal>update-widgetset</goal>
                            <goal>compile</goal>
                            <goal>compile-theme</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-clean-plugin</artifactId>
                <version>3.0.0</version>
                <configuration>
                    <filesets>
                        <fileset>
                            <directory>src/main/webapp/VAADIN/themes</directory>
                            <includes>
                                <include>**/styles.css</include>
                                <include>**/styles.scss.cache</include>
                            </includes>
                        </fileset>
                    </filesets>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>${jetty.plugin.version}</version>
                <configuration>
                    <contextPath>/login</contextPath>
                    <scanIntervalSeconds>2</scanIntervalSeconds>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

为了避免问题,我尝试删除 &lt;jetty.port&gt;8080&lt;/jetty.port&gt; 没有成功。

编辑:基于maven jetty plugin - remove localhost/server name from url

我尝试将localhost/etc/hosts更改为myapplicationname。我重新启动码头。而且,它不起作用

【问题讨论】:

    标签: java maven jetty


    【解决方案1】:

    如果我对问题的理解正确,您需要使用 80 端口作为 Jetty 的端口 (jetty.http.port),因为http://test.com/ 表示该端口是默认的 — 80。

    其他参考资料:

    1. networking - Why was port 80 chosen as the default HTTP port and 443 as the default HTTPS port? - Super User
    2. java - Change Jetty default port - Stack Overflow

    更新

    这句话稍微说明了问题:

    对不起,我不知道如何提供更多。我在 debian 上安装了 Jetty 9

    ——鲍勃,the original message

    编辑/etc/default/jetty9文件如下:

    # Additional arguments to pass to Jetty
    JETTY_ARGS=jetty.port=80
    
    # If you run Jetty on port numbers that are all higher than 1023, then you
    # do not need authbind. It is used for binding Jetty to lower port numbers.
    # (yes/no, default: no)
    AUTHBIND=yes
    

    然后,重启 Jetty 服务器:

    # service jetty9 restart
    

    【讨论】:

    • 这是我在帖子中尝试和描述的。这不会删除 URL 中的 :8080。
    • @Bob,您能否通过添加a Minimal, Complete, and Verifiable example 来更新问题,包括pom.xml 文件的内容?
    • 我添加了 pom.xml。
    • 我不认为它在我的 java 代码中......而且我的代码包含大量行。我认为它是在 maven 或 jetty 配置中
    • @Bob,如果您能提供一个最小但完整的示例来重现问题,那就太好了。
    猜你喜欢
    • 2017-03-03
    • 1970-01-01
    • 2019-10-18
    • 1970-01-01
    • 2020-10-13
    • 1970-01-01
    • 1970-01-01
    • 2014-01-17
    • 2016-11-13
    相关资源
    最近更新 更多