如何更改linux下的Apache端口号
一、修改/etc/httpd/conf/httpd.conf文件中的监听端口号
Listen 80
把80修改成需要的号,如8000,即
Listen 8000
二、查看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
发现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
想建立一个测试用的虚拟主机,遇到了这个问题:
[root@localhost 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的防火墙:
[root@localhost html]# vim /etc/sysconfig/iptables
[root@localhost 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 ]
如何更改linux下的Apache端口号相关推荐
- linux下修改mysql端口号
1.登录mysql mysql -u root -p 2.查看当前端口号 show global variables like 'port'; 3.修改端口 vim /etc/my.cnf 4. 增加 ...
- linux下tomact改变端口号,如何在Linux中修改tomcat端口号
我这里有好几个tomcat,同时使用的话就要给端口号改成不一样的: 1.首先cd进tomcat目录里的conf文件夹,vi打开server.xml配置文件 [root@localhost soft]# ...
- Linux下搭建Apache服务器
Linux下搭建Apache服务器(完整版) 什么是Apache? Apache Licence是著名的非盈利开源组织Apache采用的协议.该协议和BSD类似,同样鼓励代码共享和尊重原作者的著作权, ...
- linux 怎么配置apache,在Linux下配置Apache Web服务
<在Linux下配置Apache Web服务>由会员分享,可在线阅读,更多相关<在Linux下配置Apache Web服务(10页珍藏版)>请在人人文库网上搜索. 1.在Lin ...
- 解决如何修改linux系统mysql默认端口号3306
解决如何修改linux系统mysql默认端口号3306 修改配置文件 验证端口号 修改配置文件 找到my.cnf 文件 ,我的是在/etc/目录下 vim /etc/my.cnf 如下图所示: 找到c ...
- 如何关闭PHP的安全模式,Linux下的Apache和PHP安全设置,如何开启PHP的安全模式
Linux下的Apache和PHP安全设置 PHP安全模式开启,PHP5.3将不再有安全模式. (1) safe_mode:以安全模式运行php; 在php.ini文件中使用如下 safe_mode ...
- 在Linux下进行Apache+tomcat整合
今天为大家介绍如何在Linux下进行Apache+tomcat整合,虚拟机版本是Redhat5,ip地址为192.168.1.12,实验步骤如下: 一 安装Jdk 二 安装Apache 三 安装tom ...
- LINUX下的APACHE的配置
今天写一下LINUX下的APACHE的配置方法. APACHE是作为WEB服务器的.它的优点在于用缓存方式来加快网页的搜索速度. APACHE缺省只支持静态网页 LINUX下有APACHE的RPM包 ...
- html留言板 php,linux下使用Apache+php实现留言板功能的网站
一.首先我们的linux服务器上要安装Apache和php php的安装方法和Apache方法如同一辙 二.关闭防火墙服务,关闭selinux 请参考:http://www.cnblogs.com/d ...
最新文章
- DeepFashion︱衣物时尚元素关键点定位+时尚元素对齐技术
- 多个ERP系统连接一个EWM系统
- jQuery实现父窗口的问题
- Stack:peek、pop、push、search
- 听说Attention与Softmax更配哦~
- C++设计模式-解释器模式
- 离开载具_迷你世界 自制火箭试飞成功 飞行载具不负众望
- docker 从harbor 拉取镜像慢_kubernetes从Harbor拉取镜像imagePullSecrets如何创建
- LAMDA表达式学习
- Adjacent Bit Counts(01组合数)
- LINUX下的流量监控shell脚本
- ssis for循环容器_SSIS包中的序列容器
- 现代C++模板元编程基础
- Alpha版本发布说明
- SqlServer删除表中某几列重复的记录并保留一条
- InnoSetup 如何获取安装程序的路径?
- 稳压电源集成控制器的发展
- 线性代数-矩阵方程应用:配平化学方程式
- elementUI重难点
- 史上最严数据保护条例欧盟GDPR今日生效,你可能需要这版中文全文(下)