Score:0

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

ke flag

I'm very much new to hosting my own server. I'm following this tutorial: https://www.answertopia.com/ubuntu/setting-up-an-ubuntu-web-server/ 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 127.0.1.1. I cleared the error by adding ServerName 127.0.0.1 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/diyserv.net.conf

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.
        ServerName www.diyserv.net

        ServerAdmin [email protected]
        DocumentRoot /var/www/diyserv.net

        # 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
</VirtualHost>

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 www.diyserv.net, but not from devices on a different network. Hopefully this is just a case of needing to wait for DNS records to propogate

sotirov avatar
br flag
Please edit your question with more details, you Ubuntu version, the content of /etc/apache2/sites-available/yourdomain.conf
lief b avatar
ke flag
@sotirov I've added the information you requested
mpboden avatar
do flag
If you `nslookup www.diyserv.net`, does it resolve to your IP address? You probably need to configure the name servers through Google Domains.
lief b avatar
ke flag
@mpboden when i do that i get ```Server: 127.0.0.53 Address: 127.0.0.53#53 ** server can't find www.diyserv.net: NXDOMAIN ``` I think you're right about configuring the name server
Organic Marble avatar
us flag
Assuming www.diyserv.net is really the domain, it resolves to 75.118.49.2 for me. But it does not show a website when I go to either the URL or the domain in a browser.
Score:1
do flag

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.

John Hanley avatar
in flag
This will not work with most residential ISPs. They block ports like 80, 443. For business ISPs, this will work. I live in Seattle, and none of our residential ISPs allow port 80, 443, etc. They require you to upgrade to business class.
mpboden avatar
do flag
@JohnHanley Very true. Each residential ISP will vary, though. I’ve added a disclaimer. Thanks for the reminder.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.