linux修改http端口80,在开启selinux的情况下,如何修改httpd的端口且服务能正常使用...

本次测试将原有httpd的port 80 修改为801

[root@localhost ~]# systemctl restart httpd

Job for httpd.service failed. See ‘systemctl status httpd.service’ and ‘journalctl -xn’ for details.

[root@localhost ~]# systemctl stop httpd

[root@localhost ~]# systemctl start httpd

Job for httpd.service failed. See ‘systemctl status httpd.service’ and ‘journalctl -xn’ for details.

[root@localhost ~]# !v

vim /etc/httpd/conf/httpd.conf

#

# Change this to Listen on specific IP addresses as shown below to

# prevent Apache from glomming onto all bound IP addresses.

#

#Listen 12.34.56.78:80

Listen 801  修改为801 违返selinux

[root@localhost ~]# semanage port -l |grep http

http_cache_port_t              tcp      8080, 8118, 8123, 10001-10010

http_cache_port_t              udp      3130

http_port_t                    tcp      80, 81, 443, 488, 8008, 8009, 8443, 9000  没有801所以不能接管httpd

pegasus_http_port_t            tcp      5988

pegasus_https_port_t           tcp      5989

[root@localhost ~]#systemctl status -l httpd

10月 19 14:46:02 localhost.localdomain httpd[1452]: AH00558: httpd: Could not reliably determine the server’s fully qualified domain name, using localhost.localdomain. Set the ‘ServerName’ directive globally to suppress this message

10月 19 14:46:02 localhost.localdomain httpd[1452]: (13)Permission denied: AH00072: make_sock: could not bind to address [::]:801

10月 19 14:46:02 localhost.localdomain httpd[1452]: (13)Permission denied: AH00072: make_sock: could not bind to address 0.0.0.0:801

[root@localhost ~]# journalctl -xn

*****  Plugin catchall (1.49 confidence) suggests

10月 19 14:46:02 localhost.localdomain httpd[1452]: (13)Permission denied: AH00072: make_sock: could not bind to address [::]:801

10月 19 14:46:02 localhost.localdomain httpd[1452]: (13)Permission denied: AH00072: make_sock: could not bind to address 0.0.0.0:801   //不允许801调用本地sock

If you believe that httpd should be allowed name_bin

Then you should report this as a bug.

You can generate a local policy module to allow this

Do

allow this access for now by executing:

# grep httpd /var/log/audit/audit.log | audit2allow

# semodule -i mypol.pp    *********//selinux报错

解决方案

semanage port -a -t http_port_t -p tcp 801  将801加入selinux

http_cache_port_t              tcp      8080, 8118, 8123, 10001-10010

http_cache_port_t              udp      3130

http_port_t                    tcp      801, 80, 81, 443, 488, 8008, 8009, 8443, 9000   ///801已加入

[root@localhost ~]# systemctl status httpd.service

httpd.service – The Apache HTTP Server

Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled)

Active: active (running) since 二 2016-10-18 18:18:25 CST; 6min ago      //启动正常

Process: 49005 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=0/SUCCESS)

Main PID: 49231 (httpd)

Status: “Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec”

CGroup: /system.slice/httpd.service

[root@localhost ~]# netstat -ntlp |grep http

tcp6       0      0 :::801                  :::*                    LISTEN      49231/httpd

本地测试

[root@localhost ~]# curl http://localhost:801

test1

t2

艇3

dfdfdfdf

外部测试完成

扩展

senamage 端口 增加 类型 [] 协议 TCP/UDP 端口

semanage port -a -t http_port_t -p tcp 801

senamage 端口 修改 类型 [] 协议 TCP/UDP 端口

semanage port -m -t http_port_t -p tcp 801

senamage 端口 删除 类型 [] 协议 TCP/UDP 端口

semanage port -d -t http_port_t -p tcp 801

72054ec6d5f02dcb05cc10fa8263fa86.png

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值