After_Sunset
After_Sunset

Reputation: 714

How to properly use a domain name on an Apache server to host a webpage?

Okay, I'm running Apache Server 2.4.20 on an Arch Linux operating system. I currently have it setup and working in such a manner that requests from any outside connection get forwarded through my public static ip to the local ip thats connected to the server. Aside from setting up the port forwarding on my router and setting the /etc/http/conf/httpd.conf to Listen 80 I have not had to configure anything else to get the server running. Hmm, seemed very simple.

Now I want to move on to the next step in the process and host a domain name that I have purchased through my Apache Server. Basically, as of now, when you connect to my server it just displays my public static IP in the address bar. I want to set it up in such a manner that the domain name is displayed in the address bar NOT the IP to my server.

As of now I've been trying for three days to find the proper way to do this, it seems there is literally not a single guide anywhere that explains this step by step. I'm about 40 hrs of research into this. The bits and pieces I've gathered are

I've tried every possible combination of virtual host combinations and trying to configure my nameserver its just not working, and im wasting huge amounts of time. Can someone please write a short concise guide from start to finish on setting up a domain name on an Apache Server. I don't need particular in depth explanations of whats being done, I understand the processes individually I just don't understand the process of setting it up.

So, I would love it if someone could whip up a simple example that shows the process from start to finish, again explanations of what your're doing at each step should be kept to a minimum as anyone going through this should have done they're research at this point.

EXAMPLE:

What I Have now:

Apache Server IP: **234.34.23.2**

Someone types this in and they get served your index.html page and this IP shows in the address bar.

What I'm trying to get too:

Purchased Domain Name: www.example.com

Now when someone types this in the address bar they get served that same index.html page and this domain name remains in the address bar.

Note: I'm trying to do this for only a single domain, so I will not need an example that involves multiple virtual hosts.

Upvotes: 1

Views: 16636

Answers (1)

hjpotter92
hjpotter92

Reputation: 80653

Your research was/is accurate. All you have to do is exactly the following:

  • Use virtual hosts in httpd.conf file
  • Change the nameserver to point your domain to your server

DNS/NameServer configuration

In your DNS settings, set the A and AAAA (if you have IPV6 values) to point to your IP:

Host: @
Value: 234.34.23.2
TTL: 3600 (seconds)

Save the above and refresh your machine's DNS cache. Now, going to www.example.com should try to open 234.34.23.2. If it doesn't, you can set the CNAME value for www to be the same as your A value by:

Host: www
CNAME: @
TTL: 3600 (seconds)

Again, reload your DNS cache and try.

VitualHost

For setting up Apache so that it knows which files to server for the www.example.com domain, in your httpd.conf file, add the following section:

Listen 80
<VirtualHost *:80>
    DocumentRoot "/www/example"
    ServerName www.example.com
    ServerAlias example.com
    <Directory "/www/example">
        AllowOverride All
        Options All
        Require all granted
        # Any other directives
    </Directory>
    # Other directives here
</VirtualHost>

Reload the Apache server (or restart). That is it.

Upvotes: 6

Related Questions