How to configure a subdomain in Apache2?

How to configure a subdomain in Apache2?

In this tutorial, we will see how to configure a subdomain, specifically a third-level domain, on a Debian-based Linux server with Apache2. We’re going to use Virtual Hosts, thanks to which you can have multiple subdomains and top-level domains on the same machine, i.e. on one IP.

Can you create a virtual host on an Apache server?

Creating virtual host configurations on your Apache server does not magically cause DNS entries to be created for those host names. You must have the names in DNS, resolving to your IP address, or nobody else will be able to see your web site.

How to create virtualhost for wildcard subdomain?

Note: I’m not just changing DocumentRoot in the config, so using mod_rewrite to change the DocumentRoot variable does not fix it. Should work. The first entry will become the default if you don’t get an explicit match. So if you had app.otherexample.com point to it, it would be caught be app1.example.com.

When to use serveralias in virtual host context?

Please note that the directive ServerAlias can be used only in the virtual host context. I think in the case when all of your sub-domains points to one DocumentRoot folder, if you set ServerName in server context the result will be almost the same:

Can you create a permanent redirect in Apache?

By default, both Redirect and RedirectMatch directives establish a temporary redirect. If you would like to create a permanent redirect, you can do so by appending permanent to either of the directives: You can also create more flexible and powerful redirects with the mod_rewrite module.

Creating virtual host configurations on your Apache server does not magically cause DNS entries to be created for those host names. You musthave the names in DNS, resolving to your IP address, or nobody else will be able to see your web site.

How to create a new domain in Apache2?

Note that the /etc/apache2/sites-available directory contains configuration files for Virtual Hosts. You can either create a new configuration from scratch or copy an existing one as the basis for a second site. If you want to follow the first approach, create a file called company2.example.com with the following content:

How to set up Apache virtual hosts in Debian 8?

Apache comes with a default virtual host file called 000-default.conf that you can use as a jumping off point. Copy this file for the first domain: Note: The default Apache configuration in Debian 8 requires that each virtual host file end in .conf.

How to setup a domain with a VPS?

Connect your domain with the server so that you don’t have to access your server by typing IP Addresses. First of all, find your public IP Address from t he VPS dashboard that your provider has given you. Then head over to the Domain Dashboard settings ( In my case, it is Namecheap ).