Welcome to the Linux Foundation Forum!

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

Hello!

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:

  1. Listen 192.168.153.53:80
  2.  
  3. <VirtualHost 192.168.153.53:80>
  4. DocumentRoot /var/www/ipvhost/
  5. ServerName ipvhost.example.com
  6. <Directory /var/www/ipvhost>
  7. Options Indexes FollowSymLinks
  8. AllowOverride None
  9. Require all granted
  10. </Directory>
  11. </VirtualHost>
  12.  

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

  1. apache2.service - The Apache HTTP Server
  2. Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
  3. Active: failed (Result: exit-code) since Wed 2021-04-07 15:58:20 EEST; 6s ago
  4. Docs: https://httpd.apache.org/docs/2.4/
  5. Process: 505773 ExecStart=/usr/sbin/apachectl start (code=exited, status=1/FAILURE)
  6.  
  7. huhti 07 15:58:20 X230 systemd[1]: Starting The Apache HTTP Server...
  8. 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
  9. huhti 07 15:58:20 X230 apachectl[505776]: (99)Cannot assign requested address: AH00072: make_sock: could not bind to address 192.168.153.53:80
  10. huhti 07 15:58:20 X230 apachectl[505776]: no listening sockets available, shutting down
  11. huhti 07 15:58:20 X230 apachectl[505776]: AH00015: Unable to open logs
  12. huhti 07 15:58:20 X230 apachectl[505773]: Action 'start' failed.
  13. huhti 07 15:58:20 X230 apachectl[505773]: The Apache error log may have more information.
  14. huhti 07 15:58:20 X230 systemd[1]: apache2.service: Control process exited, code=exited, status=1/FAILURE
  15. huhti 07 15:58:20 X230 systemd[1]: apache2.service: Failed with result 'exit-code'.
  16. 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:

  1. Chassis: laptop
  2. Operating System: Ubuntu 20.04.2 LTS
  3. Kernel: Linux 5.8.0-44-generic
  4. Architecture: x86-64

Thank you!

Lionel.

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Comments

  • Posts: 115

    Hello Lionel,

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

    sudo ip addr add 192.168.153.53/24 dev eth0

    where eth0 is your network adapter

  • 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

  • Posts: 7

    Hi k0dard,

    I confirm that 192.168.153.53 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! : )

  • Posts: 115

    You're welcome :)

  • 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

  • Posts: 7

    Thank you Lee for the additional comments.

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Categories

Upcoming Training