Apache Web Server Virtual Host Configuration

  
  1. Httpd Virtual Host Configuration
  2. Apache Web Server Configuration File
  3. Apache Web Server Virtual Host Configuration Software
  4. Apache Web Server Virtual Host Configuration Tool
  • Related Questions & Answers

No Comments on List All Apache Web Server Parsed Virtual Host Configuration Settings for Debugging Maybe you don’t know what all virtual hosts your Apache HTTP Server has defined and where exactly because your config files aren’t organised well, they’re a mess. To enable HTTP/2 on your Apache web server add one of the following to your global Apache configuration or inside of a particular virtual host. Protocols h2 http/1.1. Here is the minimal virtual server configuration that can be used to enable HTTP/2 in some virtual host: ServerName example.com ServerAlias www.example.com.

  • Selected Reading
Apache Web ServerLinuxserver

Apache Virtual Hosts allows multiple websites to run on one Web server. With virtual hosts, you can specify the site document root (the directory which contains the website files), create a separate security policy for each site, use different SSL certificates for each site and much more. Running Apache in its own non-root account is good. Modify User & Group Directive in httpd.conf of your Apache Web Server. User apache Group apache Disable Signature. The Off setting, which is the default, suppresses the footer line. The On setting simply adds a line with the server version number and ServerName of the serving virtual host.

In this article, you will learn about how to set up Apache virtual hosts on an Ubuntu Linux. During this process, you will learn how to serve different sites to different users depending on the domain/site they are requesting.

Apache Web Server

The Apache web server is the most popular and powerful way of serving web sites on the internet. It is used for more than half of all the active websites on the internet and is extremely powerful and flexible.

Apache gives its functionality and the components to individual units which can be customized and configured independently. The basic unit that describes a site or a domain is called a virtual host.

This allows the administrator to use one server to host multiple domains or sites with a single interface or IP address by using a mechanism.

Apache Installation

After these steps are complete, we can get started.

For Demo purpose, we shall configure apache to make a virtual host for webserver1.com and another for webserver2.com. This will be like a reference guide, but you should substitute your own site/domains.

Create the Directory Structure

The first step here would be that, a directory structure shall hold the site information and data which will be served to visitors. By default, the top-level directory for apache is /var/www and we will be setting them to the individual directories under the /var/www directory for each site/domain.

For each of our site, we are going to make site directories –

Grant Permissions

Now, we have the directory structure of our site/domain, but they are created and owned by our root user. If we want our normal user to be able to modify files in our web directories, then we have to change the ownership to others normal users.

We should also modify our permissions a little bit to ensure that read access is permitted to the general web directory and all of the files and folders it contains so that pages can be served correctly:

Your web server should now have the permissions it needs to serve the site, and your user should be able to create content within the necessary folders.

Create Demo Pages for Each Virtual Host

First, we shall start with webserver1.com. Then, we can create an index.html file in our editor by typing:

Edit the index.html file with a simple HTML script which indicates the site it is connected to. <html>

We can then edit the file and modify the relevant pieces of information:

Create New Virtual Host Files

Virtual host files are the configuration files that specify the virtual host and instructs the Apache to respond to various domain requests.

Copy First Virtual Host file and customize for Second Domain webserver2.com

You now need to modify all of the pieces of information to reference your second domain. When you are finished, it may look something like this:

Enable the New Virtual Host Files

Now that we have already created our virtual host files, we must enable these sites. Apache has its own tools that allow us to do this.

We needed to restart Apache to make these changes take effect:

Testing the Websites

As these site/domains are not the public so no entry will be there to easy the steps we needed to edit the /etc/hosts file so that if we browse with domain names webserver1.com and webserver2.com we can see the web pages

Now that you have two hosts configured, you can test your setup easily by opening the favorite browser and open the domains.

http://webserver1.com


http://webserver2.com

After the configuration you should now have a single server handling two separate domain/site names. You can expand this process by following the steps we outlined above to make additional virtual hosts. There is no software limit for configuring the domain names Apache can handle any no of sites, we can make as many as sites/domains till your servers are capable of handling them.

This tutorial explains about Apache HTTP Server( Apache Web Server) Installation. Let us learn about what Apache HTTP Server is and how to install and configure it on a Linux Machine.

Apache http Server

Apache is a very well known open-source Web Server. It is not only popular but also very old Web Server. Like any other Web Servers, Apache also accepts requests from the clients, search for the requested queries and then send the response back to them.

Also Read : How to install Anaconda on Linux

&& Install Redis on Linux from source

Apache HTTP Server Installation

Step 1- Update your Linux Box

$ yum update -y

Step 2- Install Apache Web Server

$ yum install httpd -y

Step 3- Start httpd service

$ service httpd start

Step 5- check the httpd service status

$ service httpd status

Step 6- Run chkconfig command to run the httpd service automatically after a system reboot

$ chkconfig httpd on

Step 7- To browse website from the Internet, open port 80 for http and 443 for https in your Server firewall , Network Firewall and Security Group (If using AWS or any other cloud service)

Now your Apache-Server is installed and ready.

Configuring Apache HTTP Server

Let us understand the ApacheHtTTPServer step by step from basic to advanced.

As soon as your installation is done and port is opened in the security group, without doing any configuration change just enter the public IP in the web browser of any computer. You will see the default page as shown below.

To access the server from your domain name, create A record for your web server in your DNS zone configuration.If you are not managing your DNS Server please take help of your DNS team/IT Team to do so.

I have created A record for my domain as follows:

devopsmyway.in ————–> IP Address of my Server.

Now I can browse the Apache Web Server from my domain name i.e devopsmyway.in. The same test page will come as I did not change any configuration yet.

Basic Configuration of Apache HTTP Server

Let’s do some basic changes to open your Web Server (Web Site) as per your configuration.

Create an index.html file in “/var/www/html” directory and write some content in this to serve in the web browser. I am using echo command here to create and write content in index.html.

$ echo “Hello , Welcome to Devopsmyway.in ” > /var/www/html/index.html

Httpd Virtual Host Configuration

As soon as you create and write content in index.html file in Document Directory“/var/www/html” your website will start serving the content written in index.html.

Now we have done the basic configuration of Apache Web Server. Let us move ahead and learn some advanced settings.

Virtual Host

Virtual host comes into picture when you want to host multiple Websites on a Single Server. Virtual host are of two types:

  1. Name-based virtual host
  2. IP based virtual host

Name-based Virtual Host

Name-based Virtual Host is used to configure multiple websites on a Single Server having a single IP Address. To configure Name-based Virtual hosts we need to do configuration changes in Apache Configuration file.

Apache Configuration file : /etc/httpd/conf/httpd.conf

Apache Web Server Configuration File

Let us configure two websites www.devopsmyway.in and www.devopsmyway.net on the same Server with same IP address. To do so , open /etc/http/conf/httpd.conf and add the following lines at the bottom of the file.

$ vi /etc/httpd/conf/httpd.conf

<VirtualHost 172.31.22.60:80>
ServerAdmin [email protected]
DocumentRoot /var/www/html/devopsmyway.in
ServerName www.devopsmyway.in
ErrorLog logs/www.devopsmywa.in-error_log
CustomLog logs/www.devopsmyway.in-access_log common
</VirtualHost>

<VirtualHost 172.31.22.60:80>
ServerAdmin [email protected]
DocumentRoot /var/www/html/devopsmyway.net
ServerName www.devopsmyway.net
ErrorLog logs/www.devopsmyway.net-error_log
CustomLog logs/www.devopsmyway.net-access_log common
</VirtualHost>

Apache virtual host file location

Now Create to Directories as follows:

$ mkdir -p /var/www/html/devopmyway.net

$ mkdir -p /var/www/html/devopmyway.in

Create index.html file in each folder and add some content in it.

$ echo “Hello , Welcome to Devopsmyway.in ” > /var/www/html/devopsmyway.in/index.html

$ echo “Hello , Welcome to Devopsmyway.net ” > /var/www/html/devopsmyway.net/index.html

Now check the configuration and restart the httpd service

Apache Web Server Virtual Host Configuration Software

$ httpd -t

$ service httpd restart

Apache Web Server Virtual Host Configuration Tool

Shazam a video iphone. Note: If you donot have two websites in Public DNS , you can do host entry in /etc/hosts on the same server as follows for testing

Now you will able to browse both the URL.

IP based virtual host

IP bases virtual host is used to configure multiple websites on a Single Server with multiple IP Addresses. To configure IP-based Virtual hosts we need to do the following configuration changes in the Apache configuration file.

Let us configure two websites www.devopsmyway.in and www.devopsmyway.net on the same Server on two IP addresses. To do so , open /etc/http/conf/httpd.conf and add the following lines at the bottom of the file.

<VirtualHost 172.31.22.60:80>
ServerAdmin [email protected]
DocumentRoot /var/www/html/devopsmyway.in
ServerName www.devopsmyway.in
ErrorLog logs/www.devopsmywa.in-error_log
CustomLog logs/www.devopsmyway.in-access_log common
</VirtualHost>

<VirtualHost 172.31.27.122:80>
ServerAdmin [email protected]
DocumentRoot /var/www/html/devopsmyway.net
ServerName www.devopsmyway.net
ErrorLog logs/www.devopsmyway.net-error_log
CustomLog logs/www.devopsmyway.net-access_log common
</VirtualHost>

Again check your configuration, restart the httpd service and browse both the sites using the curl command.

I hope you enjoyed this tutorial and learned to launch Apache http Server on AWS . If you think this is really helpful, please do share my website https://devopsmyway.com to others as well. I will continue for the tutorial for Apache in my next blog. Also, please give your valuable feedback in the comment box.

If you think we helped you or just want to support us, please consider these:-

Connect to us: FacebookTwitter