今天有人要求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. 什么是Kafka?

    通过Kafka的快速入门 https://www.cnblogs.com/tree1123/p/11150927.html 能了解到Kafka的基本部署,使用,但他和其他的消息中间件有什么不同呢? K ...

  2. Eureka 缓存结构以及服务感知优化

    目录 Eureka-Client获取注册信息 Eureka-Server管理注册信息 服务感知优化 果然好记性不如烂笔头,再简单的东西不记录下来总是会忘的! 本文首先会分析eureka中的缓存架构.并 ...

  3. abap简单实现form递归

    需求:根据物料号查询下层物料清单 DATA LV_MATNR LIKE ZMARA_TEST-MATNR VALUE '000000000000000001'. DATA: LT_MAT LIKE T ...

  4. linux command line learn - get the absolute path of a file

    get the absolute path of a file in linux readlink -f filenme [heshuai@login01 3_Variation_calling]$ ...

  5. ubuntu16.04安装Ros(kinetic版本)【亲测好用】

    准备 1.ubuntu16.04 64位桌面版 ps:关于系统的下载和安装这里不做介绍,请自行百度,不是介绍重点 2.更改源 图上的几个勾默认是选上的,如果没有选上,选成上图这样(如果修改过勾,点击关 ...

  6. 数据库系统原理之SQL(三)

    数据库系统原理之SQL(三) 1. SQL的组成 1. 数据查询 2. 数据定义 3. 数据操作 4. 数据控制 2. 数据定义语言 CREATE创建数据库或数据库对象 创建数据库 ~~~ CREAT ...

  7. LoRa硬件调试-前导码

    前言 已知LoRa数据包在负载之前会有一段前导码,接收端是先检测前导码,收到前导码之后才认为有数据发送过来. 那么不同的前导码的长度会有什么影响呢? 前导码长短的优劣势 - 前导码实际上是占符号的,也 ...

  8. FILEBEAT+ELK日志收集平台搭建流程

    filebeat+elk日志收集平台搭建流程 1.         整体简介: 模式:单机 平台:Linux - centos - 7 ELK:elasticsearch.logstash.kiban ...

  9. h5中div边距去除

    style样式里面加上 <style> *{ margin:0 ;//外边距为0 padding:0;//内边距为0 } </style>

  10. 再见 Spring Boot 1.X ,Spring Boot 2.X 走向舞台中心

    2019年8月6日,Spring 官方在其博客宣布,Spring Boot 1.x 停止维护,Spring Boot 1.x 生命周期正式结束. 其实早在2018年7月30号,Spring 官方就已经 ...