Welcome to the Linux Foundation Forum!

IP/Port Virtual Hosts - Listen Directive - Lab 7.3. Create a New IP Virtual Host


I went through the HTTP server chapter 7, and read from the slide "IP/Port Virtual Hosts" that it was necessary to ensure that all the IP addresses and ports would be defined in a Listen directive.

When I came to the "Lab 7.3. Create a New IP Virtual Host", I then created a Listen directive in my ipvhost.conf file as follows:


DocumentRoot /var/www/ipvhost/
ServerName ipvhost.example.com
<Directory /var/www/ipvhost>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted

However, if the Listen directive is declared, I can not start the apache2 service, and get the following error message:

● apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Wed 2021-04-07 15:58:20 EEST; 6s ago
       Docs: https://httpd.apache.org/docs/2.4/
    Process: 505773 ExecStart=/usr/sbin/apachectl start (code=exited, status=1/FAILURE)

huhti 07 15:58:20 X230 systemd[1]: Starting The Apache HTTP Server...
huhti 07 15:58:20 X230 apachectl[505776]: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 2001:2003:fbh3:6500:904a:6dpb:92bb:6f6c. Set the 'ServerName' directive globally to suppress this message
huhti 07 15:58:20 X230 apachectl[505776]: (99)Cannot assign requested address: AH00072: make_sock: could not bind to address
huhti 07 15:58:20 X230 apachectl[505776]: no listening sockets available, shutting down
huhti 07 15:58:20 X230 apachectl[505776]: AH00015: Unable to open logs
huhti 07 15:58:20 X230 apachectl[505773]: Action 'start' failed.
huhti 07 15:58:20 X230 apachectl[505773]: The Apache error log may have more information.
huhti 07 15:58:20 X230 systemd[1]: apache2.service: Control process exited, code=exited, status=1/FAILURE
huhti 07 15:58:20 X230 systemd[1]: apache2.service: Failed with result 'exit-code'.
huhti 07 15:58:20 X230 systemd[1]: Failed to start The Apache HTTP Server.

If I comment and disable the Listen directive, the apache2 service starts, and I can succesfully test my IPvhost ans the original host as indicated in the Lab solutions.

I am confused, why it seems to be required theoretically and does not work in practice? What to do to make the Listen directive function as it should?

My system:

           Chassis: laptop
  Operating System: Ubuntu 20.04.2 LTS
            Kernel: Linux 5.8.0-44-generic
      Architecture: x86-64

Thank you!



  • k0dard
    k0dard Posts: 115

    Hello Lionel,

    Just to make sure, is the second address you've added to your network adapter right ?

    sudo ip addr add dev eth0

    where eth0 is your network adapter

  • k0dard
    k0dard Posts: 115

    If that is the case, I think the issue is overlapping Listen directives (see https://httpd.apache.org/docs/2.4/bind.html)

    By default Apache is listening on port 80 on all addresses and if you specify a new exact address I guess it's an overlap, because it already listens an all addresses...

    If you change the default configuration in /etc/apache2/ports.conf to

    Listen 192.168.153.X:80

    Where X is your network adapter address, your configuration would work

    Otherwise no need to add Listen directive in ipvhost.conf file

  • LioC
    LioC Posts: 7

    Hi k0dard,

    I confirm that was the second address added to my network adapter.

    I have removed the Listen directive from the ipvhost.conf and placed it in the '/etc/apached2/ports.conf' defining there all the hosts and all is functioning alright now!

    Thank you! : )

  • k0dard
    k0dard Posts: 115

    You're welcome :)

  • lee42x
    lee42x Posts: 380

    Thank you for all the coments and assistance.

    The lab assumes a default installation and part of the defaults for Ubuntu include a "listen 80" directive in the ports.conf file. It should be unnecessary to change or alter the default listen directive as it should listen for all ip addresses. Setting the address on on the listen directive will tell the server to only listen to the specified ip address.

    Thank you for participating, Lee

  • LioC
    LioC Posts: 7

    Thank you Lee for the additional comments.


Upcoming Training