今天有人要求tomcat服务器的访问地址不能带端口访问, 也就是说只能用80端口访问网站.

那么问题来了, Ubuntu系统禁止root用户以外的用户访问1024以下的商品, 因此tomcat

默认为8080也是有原因的.

因此,多才多艺的网友提供了普遍的两种方案:

1, 修改conf/server.xml中connector的port为80, 使用root用户运行tomcat.完美解决问题(ubuntu系统)

windows亦是修改conf/server.xml中的connector的port为80, 直接运行bin/startup.bat就行了.

2. ubuntu有个iptables NAT

即可控制访问ubuntu系统的请求通过iptables来转发,比如你访问80端口的请求,可以重定向到8080端口上去,

这样tomcat监听的8080端口就能收到80端口的访问请求了.

看一下歪国人的配置:

Iptables redirect port 80 to port 8080

The problem:

  • You have a linux server
  • Install tomcat or any other application server
  • You don't want the application server to run as root, therefore it cannot listen to any of the ports 80 (http) or 443 (https)
  • From outside, though, the application server must be accessible on ports 80 / 443

The most popular approach:

  • Create an ordinary user specificaly for the application server (ex: tomcat)
  • Configure it to listen to a port bigger than 1024 - actually Tomcat comes by default configured to 8080 instead of 80 and 8443 instead of 443
  • Redirect the incoming connections from port 80 to 8080

The redirection is done by using the following iptables commands issued in sequence. The first one will configure the machine to accept incoming connections to port 80, the second does the same for port 8080 and the third one will do the actual rerouting. Please proceed in a similar manner for ports 443 forwarded to 8443

iptables -A INPUT -i eth0 -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -i eth0 -p tcp --dport 8080 -j ACCEPT
iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080

然而事情你总以为算结束了!!!

Chain PREROUTING (policy ACCEPT)
num target prot opt source destination
1 REDIRECT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:443 redir ports 8443
2 REDIRECT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:80 redir ports 8080

Chain INPUT (policy ACCEPT)
num target prot opt source destination

Chain OUTPUT (policy ACCEPT)
num target prot opt source destination
1 REDIRECT tcp -- 0.0.0.0/0 127.0.0.1 tcp dpt:80 redir ports 8080

Chain POSTROUTING (policy ACCEPT)
num target prot opt source destination

但是:

$service iptables save

iptables: unrecognized service

WHY!??

http://m.blog.csdn.net/blog/FENGQIYUNRAN/21830541

于是准备着手解决,解决思路很是明了,就是首先确定Linux是否安装了 iptables 。

service iptables status

但是仍然提示:iptables:unrecognized service。准备安装,根据不同的Linux内核选择不同的方法如下:

yum install iptables   #CentOS系统
apt-get install iptables    #Debian系统

但是提示已经安装,那为什么状态显示是未识别的服务呢?继续找原因。继续研究发现可能是由于没有安装iptables-ipv6,于是采用

sudo apt-get install iptables-ipv6进行安装,但提示Unable to locate package错误得错误。

考虑到软件间的不兼容,无奈先进行更新:sudo apt-get update,更新后重新安装仍然无法解决定位的问题。

于是采用apt-get install iptables*进行所有可能性查找和安装。经过一轮安装后iptables:unrecognized service的问题仍然没有解决。

继续研读相关资料,最终发现问题所在:

在ubuntu中由于不存在 /etc/init.d/iptales文件,所以无法使用service等命令来启动iptables,需要用modprobe命令。
启动iptables
modprobe ip_tables
关闭iptables(关闭命令要比启动复杂)
iptables -F
iptables -X
iptables -Z
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -P FORWARD ACCEPT
modprobe -r ip_tables
依次执行以上命令即可关闭iptables,否则在执行modproble -r ip_tables时将会提示
FATAL: Module ip_tables is in use.
 
 不过, 最后这个NAT始终没有起到作用~~~~~

关于设置tomcat端口为80的事的更多相关文章

  1. LInux设置tomcat端口为80

    <Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" ...

  2. 使用AdvancedInstaller打包web工程设置tomcat端口的方法

    原文:使用AdvancedInstaller打包web工程设置tomcat端口的方法 1.首先,要把你要打包的tomcat下的server.xml文件删掉,因为tomcat自带的serv ...

  3. Linux Tomcat 80端口 Port 80 required by Tomcat v8.5 Server at localhost is already in use.

    Port 80 required by Tomcat v8.5 Server at localhost is already in use. The server may already be run ...

  4. Mac下Tomcat安装&配置&80默认端口设置

    序言: 在学习Tomcat时, 部署虚拟服务主机时,遇到了无响应的情况.原以为是应为Tomcat默认端口8080在调整至(进行端口转发设置)默认端口80会和Mac自带Apache起冲突.但是也有同学使 ...

  5. 配置Tomcat监听80端口、配置Tomcat虚拟主机、Tomcat日志

    6月27日任务 16.4 配置Tomcat监听80端口16.5/16.6/16.7 配置Tomcat虚拟主机16.8 Tomcat日志扩展邱李的tomcat文档 https://www.linuser ...

  6. Tomcat介绍、安装jdk、安装Tomcat、配置Tomcat监听80端口

    1.Tomcat介绍 2.安装jdk下载:wget -c http://download.oracle.com/otn-pub/java/jdk/10.0.1+10/fb4372174a714e6b8 ...

  7. 配置Tomcat监听80端口 配置Tomcat虚拟主机 Tomcat日志

    配置Tomcat监听80端口 • vim /usr/local/tomcat/conf/server.xml Connector port=" protocol="HTTP/1.1 ...

  8. Linux下Tomcat端口、进程以及防火墙设置

     Linux下Tomcat端口.进程以及防火墙设置 1,查看tomcat进程: #ps -aux | grep tomcat(或者ps -ef | grep tomcat都行) 可以看到现在运行着两个 ...

  9. Linux centosVMware 配置Tomcat监听80端口、配置Tomcat虚拟主机、Tomcat日志

    一.配置Tomcat监听80端口 关闭tomcat报错 [root@davery src]# /usr/local/tomcat/bin/shutdown.sh 重装tomcat即可 vim /usr ...

随机推荐

  1. 洛谷 P1939 矩阵加速(数列)

    题意简述 \(a[1]=a[2]=a[3]=1\) \(a[x]=a[x−3]+a[x−1](x>3)\) 求a数列的第n项对1000000007取余的值. 题解思路 矩阵加速 设\[ F=\b ...

  2. Flutter学习笔记(16)--Scaffold脚手架、AppBar组件、BottomNavigationBar组件

    如需转载,请注明出处:Flutter学习笔记(15)--MaterialApp应用组件及routes路由详解 今天的内容是Scaffold脚手架.AppBar组件.BottomNavigationBa ...

  3. 带图标和多行显示的ListBox

    源码https://www.codeproject.com/Articles/15464/Extending-the-ListBox-to-show-more-complex-items 定义控件 u ...

  4. EMCAscript6随心所记

    es6的支持情况http://kangax.github.io/compat-table/es6/ 1.let命令 基本用法 ES6新增了let命令,用来声明变量.它的用法类似于var,但是所声明的变 ...

  5. jenkins无法连接到git原因

    1.账号密码错误 2.公钥私钥不对应(git上为公钥,jenkins为私钥,私钥比公钥长) 3.公钥私钥文件没有复制到jenkins目录下的.ssh文件中

  6. var let及const

    es6已经发布很久了,之前只会用var定义变量,学习了let和const后,又学到了一些作用域.JavaScript编译和深拷贝浅拷贝的知识.这章主要来说说这三个定义量的方法: 1.var 在没学习e ...

  7. 使用Python的Django和layim实现即时通讯

    看到Django和layim实现websocketde资料很少,自己就琢磨了下,顺便搭建出来了.自己要去找闲心大神授权呀. 先来看图  这是初次搭建的,今天一天就搞定.我自己接入了图灵机器人. Pyt ...

  8. 在 Web 级集群中动态调整 Pod 资源限制

    作者阿里云容器平台技术专家 王程阿里云容器平台技术专家 张晓宇(衷源) ## 引子 不知道大家有没有过这样的经历,当我们拥有了一套 Kubernetes 集群,然后开始部署应用的时候,我们应该给容器分 ...

  9. pytest-html报告修改与汉化

    前言 Pytest框架可以使用两种测试报告,其中一种就是使用pytest-html插件生成的测试报告,但是报告中有一些信息没有什么用途或者显示的不太好看,还有一些我们想要在报告中展示的信息却没有,最近 ...

  10. 迁移桌面程序到MS Store(10)——在Windows S Mode运行

    首先简单介绍Windows 10 S Mode,Windows在该模式下,只能跑MS Store里的软件,不能通过其他方式安装.好处是安全有保障,杜绝一切国产流氓软件.就像iOS一样,APP进商店都需 ...