How to configure Apache2 on Ubuntu Server to use a domain name

I’m very much new to hosting my own server. I’m following this tutorial: and I’ve gotten to the section titled "1.7 Configuring the Apache Web Server for Your Domain". I’ve followed all the steps but when I get to the part where I test the configuration it throws an error because it can’t use ip I cleared the error by adding ServerName to /etc/apache2/apache2.conf but when I go to the domain name, the webpage still doesn’t show up, and if I go to the ip address, only the default page shows. I’m assuming that the ServerName command in apache2.conf is the cause of my troubles but maybe there’s something else there?

if it helps, I purchased my domain name through google domains.

Edit: I am using ubuntu server 23.04

Here is the content of /etc/apache/sites-available/

VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.

        DocumentRoot /var/www/

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf

Edit: I edited my router settings and set up port forwarding, and I added A records to google domains, and now I can access the webpage from devices on the same network at, but not from devices on a different network. Hopefully this is just a case of needing to wait for DNS records to propogate

Asked By: lief b


I’m unable to access the server with either the domain name or its IP, which is now known since you’ve updated your A Records. If you can access on local network and not from another network, then the problem is with your router not allowing access. You need to allow port forwarding on WAN interface of router on port 80 to your servers IP address on port 80.

As an example, I have a pfSense router. To configure a port forward from the WAN address to the server, it looks like the following:

enter image description here

Now having said that, this may or may not work for you. Residential ISPs may or may not block ports 80, 443, etc. So your mileage may vary.

Answered By: mpboden
Categories: Answers Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.