如何让Tomcat 7在Windows Server 2008上的端口80上运行?

时间:2014-12-28 04:47:50

标签: java apache tomcat tomcat7 windows-server-2008

我花了两天时间试图让它发挥作用。

当我第一次启动Tomcat 7时,它在端口8080上运行,这是Tomcat的默认设置。因此可以访问它,但输入:http://localhost:8080/mydomain.com:8080

但是我希望从端口8080移到端口80,这样我就可以输入mydomain.com并转到网页。

我已禁用可在IIS,MSSQL,万维网发布等端口80上运行的所有额外服务。

server.xml文件中,我做了以下更改:

<Connector port="80" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />

然后当我启动服务器时,我在日志中得到了这个(尽管服务器启动了):

...
Dec 27, 2014 9:34:44 PM org.apache.coyote.AbstractProtocol init
SEVERE: Failed to initialize end point associated with ProtocolHandler ["http-apr-80"]
java.lang.Exception: Socket bind failed: [730048] Only one usage of each socket address (protocol/network address/port) is normally permitted.  
    at org.apache.tomcat.util.net.AprEndpoint.bind(AprEndpoint.java:453)
    at org.apache.tomcat.util.net.AbstractEndpoint.init(AbstractEndpoint.java:646)
    at org.apache.coyote.AbstractProtocol.init(AbstractProtocol.java:434)
    at org.apache.catalina.connector.Connector.initInternal(Connector.java:978)
    at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
    at org.apache.catalina.core.StandardService.initInternal(StandardService.java:559)
    at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
    at org.apache.catalina.core.StandardServer.initInternal(StandardServer.java:821)
    at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
    at org.apache.catalina.startup.Catalina.load(Catalina.java:638)
    at org.apache.catalina.startup.Catalina.load(Catalina.java:663)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:280)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:454)

Dec 27, 2014 9:34:44 PM org.apache.catalina.core.StandardService initInternal
SEVERE: Failed to initialize connector [Connector[HTTP/1.1-80]]
org.apache.catalina.LifecycleException: Failed to initialize component [Connector[HTTP/1.1-80]]
    at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:106)
    at org.apache.catalina.core.StandardService.initInternal(StandardService.java:559)
    at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
    at org.apache.catalina.core.StandardServer.initInternal(StandardServer.java:821)
    at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
    at org.apache.catalina.startup.Catalina.load(Catalina.java:638)
    at org.apache.catalina.startup.Catalina.load(Catalina.java:663)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:280)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:454)
Caused by: org.apache.catalina.LifecycleException: Protocol handler initialization failed
    at org.apache.catalina.connector.Connector.initInternal(Connector.java:980)
    at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
    ... 12 more
Caused by: java.lang.Exception: Socket bind failed: [730048] Only one usage of each socket address (protocol/network address/port) is normally permitted.  
    at org.apache.tomcat.util.net.AprEndpoint.bind(AprEndpoint.java:453)
    at org.apache.tomcat.util.net.AbstractEndpoint.init(AbstractEndpoint.java:646)
    at org.apache.coyote.AbstractProtocol.init(AbstractProtocol.java:434)
    at org.apache.catalina.connector.Connector.initInternal(Connector.java:978)
    ... 13 more

Dec 27, 2014 9:34:44 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-apr-8009"]
Dec 27, 2014 9:34:44 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 3310 ms
Dec 27, 2014 9:34:44 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Dec 27, 2014 9:34:44 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.57
Dec 27, 2014 9:34:44 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\Apache\tomcat\webapps\docs
Dec 27, 2014 9:34:46 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory C:\Apache\tomcat\webapps\docs has finished in 1,985 ms
Dec 27, 2014 9:34:46 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\Apache\tomcat\webapps\examples
Dec 27, 2014 9:34:47 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory C:\Apache\tomcat\webapps\examples has finished in 1,234 ms
Dec 27, 2014 9:34:47 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\Apache\tomcat\webapps\host-manager
Dec 27, 2014 9:34:48 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory C:\Apache\tomcat\webapps\host-manager has finished in 453 ms
Dec 27, 2014 9:34:48 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\Apache\tomcat\webapps\manager
Dec 27, 2014 9:34:48 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory C:\Apache\tomcat\webapps\manager has finished in 313 ms
Dec 27, 2014 9:34:48 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\Apache\tomcat\webapps\ROOT
Dec 27, 2014 9:34:48 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory C:\Apache\tomcat\webapps\ROOT has finished in 156 ms
Dec 27, 2014 9:34:48 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-apr-8009"]
Dec 27, 2014 9:34:48 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 4282 ms

当我访问网址mydomain.com

时,看不到任何内容

我对此非常陌生 - 已经通过大量的在线帖子并遵循说明但似乎没有任何效果。我之前做过同样的步骤,它起到了一种魅力。

我现在该怎么办?请帮忙。

这是我在netstat

上得到的

netstat result

1 个答案:

答案 0 :(得分:2)

其他一些应用正在使用端口80.使用netstart执行本地端口扫描和打印可执行路径(此视频将有助于: https://www.youtube.com/watch?feature=player_detailpage&v=V3nWkr7v4-E#t=7

通常是它的Skype(或其他聊天或点对点文件共享应用)。关闭skype(退出不只是退出,进程应该退出)然后启动tomcat。然后可以重新启动Skype,它将在其他一些端口上正常工作。

是否有任何防火墙入口阻止Java绑定到此端口?可以从防火墙规则中检查 - 如果您使用控制面板中的默认窗口防火墙。 https://www.youtube.com/results?search_query=widows+firewall+java+allow这些结果或常规搜索引擎中的相同术语将告诉您允许Java的步骤。通常Windows会在您第一次运行应用程序时询问。所以如果你说不,那就记得那个。还需要具有管理员角色(登录/或提示用户)才能进行这些更改。对于某些问题也有助于打开管理控制台。右键单击cmd.exe并选择以管理员身份运行,在安全提示中输入yes。

该程序可能有所帮助,将其保存到名为&#34; PortCheck.java&#34;

的文件中
    class PortCheck{
    public static void main(String []args) throws Exception{
        String port = "80";
        if(args.length > 0)port = args[0];
        final int p = Integer.parseInt(port);
        Thread t = new Thread(){
            public void run(){

                try{
                    java.net.ServerSocket s = new java.net.ServerSocket(p);
                    System.out.println("\nListening on port " + p);
                    s.accept();
                }catch(Exception e){
                    System.out.println("Err " + e);
                }
            }
        };
        t.start();
        Thread.sleep(2000);
        System.out.println("Bye ");
        System.exit(0);
    }
}

编译

  

javac c:\ _ your_path \ PortCheck.java

并运行它:

  

java -cp c:\ _ your_path PortCheck

如果成功绑定到80将告诉你:

  

收听端口80   再见

可以尝试使用443端口