Couldn't access CentOS httpd

13,039

Solution 1

Packages installed on RHEL/CentOS/Fedora systems aren't supposed to start any services automatically (because maybe you're not ready to expose your service to the world until after you've configured it).

Running service httpd start will start the service temporarily, but it won't start next time you boot. You want systemctl enable httpd to enable the service to start automatically when you boot your system.

You could check if the firewall is actually disabled. Run iptables -S to see the current ruleset. The default iptables configuration typically allows only ssh and nothing else.

Update

Your system is probably running firewalld to manage the firewall. Try service firewalld stop.

You can run systemctl disable firewalld to prevent it from starting next time your system boots.

Solution 2

-- CentOS 7

add the following to '/etc/httpd/conf/httpd.conf'

Replace:
Listen 80

With:
Listen 0.0.0.0:80

this will disable ipv6 and enable ipv4

To check this type:

netstat -an | grep -i tcp | grep -i listen

restart apache service

systemctl restart httpd.service

Also, enable firewall to access port 80

firewall-cmd --permanent --add-service=http
firewall-cmd --reload
Share:
13,039
packetie
Author by

packetie

Love to program packets, whether it's packet analysis or traffic generation.

Updated on September 10, 2022

Comments

  • packetie
    packetie over 1 year

    I have been using Ubuntu, just recently started to work on Centos (CentOS Linux release 7.1.1503 (Core)) running in VMplayer on my desktop (Ubuntu).

    • Branch new CentOS installation.
    • installed httpd (using "yum")
    • for some reason, httpd didn't start automatically, I ran "service httpd start" and it started according to "netstat -antp".

      [root@localhost ~]# netstat -antp
      Active Internet connections (servers and established)
      Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
      tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1161/sshd           
      tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1620/master         
      tcp        0      0 10.0.0.19:22            10.0.0.7:20383          ESTABLISHED 2421/sshd: root@pts 
      tcp6       0      0 :::80                   :::*                    LISTEN      2453/httpd          
      tcp6       0      0 :::22                   :::*                    LISTEN      1161/sshd           
      tcp6       0      0 ::1:25                  :::*                    LISTEN      1620/master 
      
    • I can access the http server locally (curl http://localhost within the CentOs command line)

    • when I tried access httpd from the host curl http://172.16.13.143/, it refused the TCP connection. I was able to to ssh into it, it works ok for ssh ssh [email protected].
    • I have stopped iptables service iptables stop
    • SELinux is turned off according to getenforce command.

    I just need to do a quick test on the web interface but I can't. Really need some help. Thanks.

  • Marc B
    Marc B almost 9 years
    if it wasn't running, then why is there httpd on :::80, then?
  • larsks
    larsks almost 9 years
    It is running. It just would't run if he were to reboot.
  • packetie
    packetie almost 9 years
    Thanks @larsks for the answer. I enabled the service now (so next time I reboot the guest OS, httpd will be on automatically). I got a long list of entries in iptables -S. How do I disable iptables? I don't need any protection since it's development box. Tried service iptables stop but didn't work (can't establish a TCP connection to httpd from my desktop).
  • larsks
    larsks almost 9 years
    See my update. Your system is probably using "firewalld" to manage the local firewall.