Jetty:隐藏URL中的端口号

时间:2017-11-17 19:25:37

标签: java maven jetty

我购买域名:test.com

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

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

当我访问我的网站(http://test.com)时,它无法正常工作,我需要添加端口号,例如:http://test.com:8080,这非常脏。所以,我想删除或隐藏此端口号。

我尝试使用端口号运行jetty,如:

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。
  • 的Maven。
  • 码头。

我应该在哪里管理这个?

编辑:

根据需要,这是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>

为了防止提问,我试图删除 <jetty.port>8080</jetty.port>没有成功。

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

我尝试将localhost更改为/etc/hosts的myapplicationname。我重新开始码头。并且,它无法正常工作

1 个答案:

答案 0 :(得分:-1)

如果我正确理解了问题,您需要将80端口用作Jetty的端口(jetty.http.port),因为http://test.com/表示端口是默认端口--80。< / p>

其他参考资料:

  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
  3. 更新

    这句话澄清了一点问题:

      

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

         

    - Bob,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