How to Configure Nginx and Apache virtual host configuration

Written by Alex


Apache and Nginx are the 2 commonest open source web servers within the world. Together, they’re liable for serving over 50% of traffic on the web. Both solutions are capable of handling diverse workloads and dealing with other software to supply an entire web stack. We will install Apache And Nginx virtual host configuration.

Installation Process

Install epel-release repository

# yum install yum install epel-release

Install Apache or Nginx using the below command.

# yum install httpd
# yum install nginx

Start web-server Nginx or Apache

# systemctl start httpd
# systemctl start nginx

Enable the webserver on server startup

# systemctl enable httpd
# systemctl enable nginx

Apache virtual host configuration

  1. Log on to the server using ssh.
  2. Change directory
# cd /etc/httpd/conf.d
# vi sitename.conf

3. Copy the below contents

<VirtualHost *:80>
ServerAdmin [email protected]
ServerName www.websitename
DocumentRoot /path/to/project/code
ErrorLog logs/error.log
CustomLog logs/access.log combined
<Directory "/path/to/project/code">
Options -Indexes +FollowSymLinks +MultiViews
AllowOverride all

Configuring virtual host for Nginx

  1. Connect server using ssh.
  2. Go to the configuration directory and create a virtual host config file in it. You can create a configuration file on the sites-enabled folder. conf.d folder includes in main Nginx config file.
# cd /etc/nginx/conf.d
# vi sitename.conf

3. Copy the below contents

server {
		listen 80;
		root /path/to/project/code;
        index index.html index.htm index.nginx-debian.html;

        location / {
                try_files $uri $uri/ =404;

Logon to DNS control panel and make A record with respect to server IP pointing to server URL can be accessed by web-browser. You can add cname record also.


Now you are able to know how to Install Apache And Nginx virtual host configuration.

We hope you are like this article and this is useful for you. If you learn more about Linux, AWS Tips, and Tricks Please Bookmark this Website. We are Daily Publish New Article in this Website WWW.BPMTECHGURU.IN and all post on this website is practically tested and 100% Work if you have any Problem Please Drop a Comment we are trying to resolve your problem.

About the author


Leave a Comment