如何更改linux下的Apache端口号

一、修改/etc/httpd/conf/httpd.conf文件中的监听端口号

Listen 80

把80修改成需要的号,如8000,即

Listen 8000

二、查看SELinux下http相关端口

检查SELinux是否启用 # sestatus -v |grep SELinux

SELinux status:  enabled    #表示启用

检查semanage是否安装 # rpm -qa |grep policycoreutils-python

若未安装,请先安装工具包  # yum install policycoreutils-python

# semanage port -l|grep http

http_cache_port_t              tcp      3128, 8080, 8118, 10001-10010

http_cache_port_t              udp      3130

http_port_t                    tcp      80, 443, 488, 8008, 8009, 8443

pegasus_http_port_t            tcp      5988

pegasus_https_port_t           tcp      5989

发现8000不在其范围之内,所以需要另外添加,方法如下:

# semanage port -a -t http_port_t -p tcp 8000

再次查看,

# semanage port -l|grep http

http_cache_port_t              tcp      3128, 8080, 8118, 10001-10010

http_cache_port_t              udp      3130

http_port_t                    tcp      8000, 80, 443, 488, 8008, 8009, 8443

pegasus_http_port_t            tcp      5988

pegasus_https_port_t           tcp      5989

三、在防火墙中开放新添加的端口

修改/etc/sysconfig/iptables文件,在文件中添加如一行:

-A INPUT -m state --state NEW -m tcp -p tcp --dport 8008 -j ACCEPT

四、重启防火墙和Apache

# service iptables restart

# service httpd restart

五、正常情况下,应该可以通过新端口访问WEB服务了。

注:

1、第二、三、四步骤是在系统已经开启SELinux和防火墙的情况下设置的,如果已经关闭此两个服务,修改端口后直接重启Apache即可;

2、修改的端口号可以是执行#semanage port -l|grep http后,默认已经有的端口,如8443,这样可以省略额外添加SELinux端口操作;

3、第三步操作可以图形界面下完成。

参考资料

1、Permission denied: make_sock: could not bind to address

http://emmune.blogspot.com/2009/07/permission-denied-makesock-could-not.html

不熟悉python、plone、zope,想用apache。80端口已经不在,就征用81端口凑合吧。修改httpd.conf后apachectl start,结果:

(13)Permission denied: make_sock: could not bind to address [::]:81

(13)Permission denied: make_sock: could not bind to address 0.0.0.0:81

查一下SELinux下http相关端口 semanage port -l|grep http,结果:

http_cache_port_t tcp 3128, 8080, 8118, 10001-10010

http_cache_port_t udp 3130

http_port_t tcp 80, 443, 488, 8008, 8009, 8443

pegasus_http_port_t tcp 5988

pegasus_https_port_t tcp 5989

直接用man semanage最后例子中的一句

# Allow Apache to listen on port 81

semanage port -a -t http_port_t -p tcp 81

然后再apachectl start,OK。使用域名:81能够访问啦。

注:semanage

semanage is used to configure certain elements of SELinux policy without
requiring modification to or recompilation from policy sources. This
includes the mapping from Linux usernames to SELinux user identities
(which controls the initial security context assigned
to Linux users when they login and bounds their authorized role set) as
well as security context mappings for various kinds of objects, such as
network ports, interfaces, and nodes(hosts) as well as the file context
mapping. See the EXAMPLES section below
for some examples of common usage. Note that the semanage login command
deals with the mapping from Linux usernames (logins) to SELinux user
identities, while the semanage user command deals with the mapping from
SELinux user identities to authorized role
sets. In most cases, only the former mapping needs to be adjusted by
the administrator; the latter is principally defined by the base policy
and usually does not require modification.

2、linux 下apche无法监听端口解决办法

http://www.zzxj.net/blog/fxs_2008/archive/2010/07/05/187.html

想建立一个测试用的虚拟主机,遇到了这个问题:

[[email protected] html]# service httpd start

Starting httpd: httpd: Could not reliably determine the server‘s fully
qualified domain name, using localhost.termwikidev for ServerName

(13)Permission denied: make_sock: could not bind to address [::]:81

(13)Permission denied: make_sock: could not bind to address 0.0.0.0:81

no listening sockets available, shutting down

Unable to open logs

解决办法:

semanage port -l|grep http

semanage port -a -t http_port_t -p tcp 81

这个两个命令一是查看,一个是添加,添加完再查看一遍,如果有81,则成功。另可能要以root用户运行。

此外,如果要外网访问,还要打开linux的防火墙:

[[email protected] html]# vim /etc/sysconfig/iptables

[[email protected] html]# service iptables restart

重启apache.

相关资料:

starting httpd 13 permission denied make_sock could not bind to
address2010年01月19日 星期二 11:33In Fedora Core 5/6 and RHEL 5. We have made
it easier to customize certain common parts of SELinux. In previous
releases of SELinux if you wanted to change simple things
like which port a daemon could listen to, you would need to write
policy. Now we have the semanage utility.

SELinux assigns types to all network ports on a system. By default all
ports are less then 1024 are labeled reserved_port_t and all ports >
1024 are labeled port_t. If a port is assigned to a particular type

say the http port 80, it has an assigned type of http_port_t. If you
want to look at all the assigned ports in SELinux, you can use the
semanage tool, semanage port -l.

So if you executed

semanage port -l | grep http

http_cache_port_t tcp 3128, 8080, 8118

http_cache_port_t udp 3130

http_port_t tcp 80, 443, 488, 8008, 8009, 8443

pegasus_http_port_t tcp 5988

pegasus_https_port_t tcp 5989

Here we see http_port_t is assigned to ports 80, 443, 488, 8008, 8009, 8443

The policy is written to allow httpd_t http_port_t:tcp_socket name_bind;

This means the apache command can "bind" to an port that is labeled http_port_t.

So lets say you want to run httpd on port 81.

So you edit /etc/httpd/http.conf

and change this line

Listen 80

to

Listen 81

Now restart the daemon.

service httpd restart

Stopping httpd: [ OK ]

Starting httpd: (13)Permission denied: make_sock: could not bind to address [::]:81

(13)Permission denied: make_sock: could not bind to address 0.0.0.0:81

no listening sockets available, shutting down

Unable to open logs

[FAILED]

Now the daemon fails to start because it can not bind to port 81.

This generates an AVC that looks like

----

time->Tue Dec 12 17:37:49 2006

type=SYSCALL msg=audit(1165963069.248:852): arch=40000003 syscall=102
success=no exit=-13 a0=2 a1=bf96a830 a2=b5b1e8 a3=9e58b68 items=0
ppid=21133 pid=21134 auid=3267 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0
sgid=0 fsgid=0 tty=pts10 comm="httpd" exe="/usr/sbin/httpd"
subj=user_u:system_r:httpd_t:s0 key=(null)

type=AVC msg=audit(1165963069.248:852): avc: denied { name_bind } for
pid=21134 comm="httpd" src=81 scontext=user_u:system_r:httpd_t:s0
tcontext=system_u:object_r:reserved_port_t:s0 tclass=tcp_socket

To fix this you can use semanage to add the port

semanage port -a -t http_port_t -p tcp 81

service httpd start

Starting httpd: [ OK ]

原文地址:https://www.cnblogs.com/hhjwqh/p/8361943.html

时间: 2024-11-08 08:20:32

如何更改linux下的Apache端口号的相关文章

【修改端口号】linux下修改apache,nginx服务端口号

一.linux下修改apache端口号 yum安装后,apache配置文件: /etc/httpd/conf/httpd.conf 找到apache目录下的 httpd.conf, 使用vi 打开,找到 port=80 这一行, 把80改成在此服务器上没有用到的端口号,保存退出. 二.linux下修改nginx端口号 yum安装后,nginx配置文件路径:/nginx/nginx-1.8.0/conf/nginx.conf 把80改成在此服务器上没有用到的端口号

Linux下使用Apache的Httpd+Mod_jk+Tomcat搭建Web集群服务

Linux下使用Apache的Httpd+Mod_jk+Tomcat搭建Web集群服务 目的 ?? 使用多个tomcat服务器来对请求进行分流,防止单个服务器压力过重.这里为了简单,只使用两个tomcat. 软件 apache httpd-2.2.31(下载地址:https://httpd.apache.org/download.cgi) apache tomcat-7.0.69(下载地址:https://tomcat.apache.org/download-70.cgi) tomcat-con

Linux下使用Apache搭建Web网站服务器

Linux下使用Apache搭建Web网站服务器 实验目标 apache服务器常见概念 apache服务器安装及相关配置文件 实战: 例1:为公司内网搭建一个web服务器 例2:取消apache默认欢迎页: 例3:使用rpm搭建lamp 环境 例4, 使用别名,引用网站根目录以外的路径. 例6:打开软链接功能. 通过软件链接直接引用网站根目录以外的内容 例5,当一个目录下没有默认首页时,访问http://192.168.1.63/phpmyadmin/禁止显示目录列表 例7:通过用户认证的方式,

关于linux下卸载apache后安装apache

事实说明,好记性不如烂笔头,更何况没有好记性就更需要做一些必要的记录了,因为随着时光的流逝,很多事情会渐渐的忘记,这时如果看一下之前的笔记就能事半功倍了! 以前在linux下配置了一个系统监视软件zabbix,总体用起来还不错,因为需要在网页端显示,所以需要搭建lamp环境,然后配置apache2使打开本地网页就显示那个为主页,以后就没再碰过,也没做记录,当时的配置文件和信息早已经忘记,后来胡搞了一通,发现apache服务运行不了了,打开里面的配置文件发现里面都是空的,没有任何信息,于是我开始了

Linux下搭建Apache服务器(完整版)

Linux下搭建Apache服务器(完整版) 什么是Apache? Apache Licence是著名的非盈利开源组织Apache采用的协议.该协议和BSD类似,同样鼓励代码共享和尊重原作者的著作权,同样允许代码修改,再发布(作为开源或商业软件).需要满足的条件也和BSD类似 Apache主要特点 1.开放源代码.跨平台应用 2.支持多种网页编程语言 3.模块化设计 .运行稳定.良好的安全性 Apache软件版本 1.X  1.目前最高版本是1.3,运行稳定  2.向下兼容性较好,但缺乏一些较新

linux下的apache服务自启动的几种方式

1,如果是安装包安装在Linux系统下,那么可以使用 [[email protected] ~]# service httpd restart 从而可以开启或者重启apache服务 与此同时,它的标准方式是: [[email protected] ~]# /etc/rc.d/init.d/httpd start 或者[[email protected] ~]# /etc/rc.d/init.d/httpd stop 或者[[email protected] ~]# /etc/rc.d/init.

Linux下查看Apache的请求数

在Linux下查看Apache的负载情况,以前也说过,最简单有有效的方式就是查看Apache Server Status(如何开启Apache Server Status点这里),在没有开启Apache Server Status的情况下,或安装的是其他的Web Server,比如Nginx的时候,下面的命令就体现出作用了. ps -ef|grep httpd|wc -l命令#ps -ef|grep httpd|wc -l1388统计httpd进程数,连个请求会启动一个进程,使用于Apache服

linux下安装apache详解

下载httpd-2.2.6.tar.bz2  把httpd-2.2.6.tar.bz2放到/soft 下[[email protected] ~]#cd /soft[[email protected] soft]#tar jxvf httpd-2.2.6.tar.bz2    //解压apache的压缩包[[email protected] soft]#cd httpd-2.2.6     //定位到httpd-2.2.6 文件夹下[[email protected] httpd-2.2.6]#

Linux下使用Apache实现域名转发(Tomcat/JBOSS)

Linux下安装.配置JDK就不细说了,网上的资料很多; 在安装apache时可能会遇到诸多问题,譬如APR not found,pcre-config for libpcre not found等问题,这都是和系统的具体环境有关,详细的解决办法这里不细说,推荐几个解决的方案,可以综合起来根据具体情况排查问题,千万不要过于依赖某一个方案,要对症下药,链接地址: http://www.cnblogs.com/JemBai/archive/2012/11/07/2759139.html http:/