Linux 为什么 Tomcat 可以使用端口 8080 而不是 80?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10450045/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why does Tomcat work with port 8080 but not 80?
提问by Dominik
I have started and tested Tomcat under Port 8080 (default). Now I altered the connector port to 80 and restarted Tomcat, nothing will show on my minimal Debian 6.0 installation. Now where is the trick here?
我已经在端口 8080(默认)下启动并测试了 Tomcat。现在我将连接器端口更改为 80 并重新启动 Tomcat,在我的最小 Debian 6.0 安装中不会显示任何内容。现在诀窍在哪里?
<Connector port="80" protocol="HTTP/1.1"
connectionTimeout="20000"
URIEncoding="UTF-8"
redirectPort="8443" />
采纳答案by Dominik
go to /etc/default/tomcat6 and change #AUTHBIND=no
to AUTHBIND=yes
转到 /etc/default/tomcat6 并更改#AUTHBIND=no
为AUTHBIND=yes
# If you run Tomcat on port numbers that are all higher than 1023, then you
# do not need authbind. It is used for binding Tomcat to lower port numbers.
# NOTE: authbind works only with IPv4. Do not enable it when using IPv6.
# (yes/no, default: no)
#AUTHBIND=no
回答by rooftop
Did you start Tomcat on port 80 as root? You have to be root to bind to ports <= 1024 in Linux.
您是否以 root 身份在端口 80 上启动了 Tomcat?您必须是 root 才能绑定到 Linux 中 <= 1024 的端口。
回答by Satya
stop apache service and then run tomcat you should be good , by default apache is running on port 80
停止apache服务然后运行tomcat你应该没问题,默认情况下apache在端口80上运行
回答by Jon Skeet
Two typical reasons:
两个典型原因:
- You quite possibly don't have permission to listen to a port lower than 1024 (usually requires administrative privileges, e.g. being
root
) - Something else may already be listening on port 80 (e.g. apache)
- 您很可能没有权限侦听低于 1024 的端口(通常需要管理权限,例如 be
root
) - 其他东西可能已经在侦听端口 80(例如 apache)
回答by Jesus
If nothing of the commented before works (like it happened to me), you can direct the traffic from the port 80
to the 8080
.
如果之前的评论都不起作用(就像发生在我身上一样),您可以将流量从端口引导80
到8080
.
To do it:
去做吧:
http://forum.slicehost.com/index.php?p=/discussion/2497/iptables-redirect-port-80-to-port-8080/p1
http://forum.slicehost.com/index.php?p=/discussion/2497/iptables-redirect-port-80-to-port-8080/p1
In a nutshell, type this three commands in a terminal:
简而言之,在终端中输入这三个命令:
$ sudo iptables -A INPUT -i eth0 -p tcp --dport 80 -j ACCEPT
$ sudo iptables -A INPUT -i eth0 -p tcp --dport 8080 -j ACCEPT
$ sudo iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080
回答by Arvind Sridharan
Run your startup script as root after changing the binding.
更改绑定后,以 root 身份运行启动脚本。
sudo ./<path to tomcat bin director>/startup.sh
回答by user1462586
You can use authbind/privbind or capabilities to bind to port 80.
您可以使用 authbind/privbind 或功能绑定到端口 80。