Virtual

--------

Configuring a New Directory

If you are hosting multiple websites, a good rule of thumb is to follow standard naming conventions. Let’s use cPanel’s standard naming and create a directory.

mkdir -p /var/www/yourdomain.com/public_html

Next thing you need is an index page. This will help you test the configuration.

vi /var/www/yourdomain.com/public_html/index.html

For testing purposes, input a single line of text in index.html. Save and close the file.

Change Linux file permissions, so that data can be accessed online.

chmod 755 /var/www/yourdomain.com/public_html

Try opening the index.html page. It should be available online.

Creating a Virtual Server:

We must setup at least one virtual server for Nginx, in order to process the HTTP request by Nginx. When Nginx process the request,  it looks for the server directive which is placed in http context. You can add multiple server directives, to define multiple virtual servers.

Default virtual server config can be found under    cd /etc/nginx/conf.d  directory, if you open and see that; first line itself a virtual server for localhost and listening on port 80.

server {

listen       80;

server_name  localhost;

}

You will find the location directive, which will tell the server to look for the static file when the requests comes for the localhost.

location / {

root   /usr/share/nginx/html;

index  index.html index.htm;

}

Additionally you can mention the error pages.

error_page   500 502 503 504  /50x.html;

location = /50x.html {

root   /usr/share/nginx/html;

}

The above is the minimum configuration for a virtual server, you can find the full configuration here.

Example:

The following virtual server will accept the request for server.itzgeek.com, create a configuration file  in   vi /etc/nginx/conf.d or copy the default configuration file.

cp /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/worldcm.conf

Edit in such a way that, it receives the request. Minimal configuration will look like below.

vi /etc/nginx/conf.d/worldcm.conf

server {

listen       80;

server_name  server.worldcm.net;

location / {

root   /usr/share/nginx/html/worldcm;

index  index.html index.htm;

}

}

Create root directory.

mkdir /usr/share/nginx/html/worldcm

Create Index.html page.

echo “This is WorldCM Home” > /usr/share/nginx/html/worldcm/index.html

Restart the Nginx service.

systemctl restart nginx.service

Test with browser, url will be http://server.worldcm.net

CentOS 7 – Nginx Virtual Ser

--------