The idea of this article is to change the default layout to one more in keeping with the CentOS' style. Installing Nginx via the package manager creates this layout automatically - we need to do it by hand.

Layout

As alluded to, the layout we want to create is the same as if we installed Nginx via the package manager.

The main difference being that virtual hosts will now be defined in a 'virtual.conf' file and SSL enabled virtual hosts will be defined in a 'ssl.conf' file. Both configuration files are located in a 'conf.d' folder.

This makes for easy administration to avoid confusion between the main Nginx configuration and your Vhost settings.

Folders

Let's start by creating the conf.d folder (remember Nginx was installed into '/usr/local/nginx'):

sudo mkdir /usr/local/nginx/conf/conf.d

Done.

The conf.d directory is used to store other configuration files that while separate from the main Nginx configuration file, can be used in the same manner.

Configuration

Now we need to adjust the main Nginx configuration file to look in the conf.d folder for our standard and SSL enabled Vhosts:

sudo nano /usr/local/nginx/conf/nginx.conf

I won't list the contents of the file here but note that the vast majority of the contents consists of three virtual hosts - a default for port 80, a second example Vhost, and a default for port 443. The latter of the two are actually commented out.

This is a great example of an unwieldy file. We want to condense this file for easier reading and navigation.

The easiest thing is to delete the contents of the file (you can make a copy if you wish) and replace it with this:

Restart

Restart Nginx:

sudo /etc/init.d/nginx restart

Navigating to your Server IP will show the default "Welcome to nginx!' page.

Done.

All very simple and very organized.

Summary

Mirroring the layout used when installing Nginx via the Yum package manager allows for much easier administration of your virtual hosts. The standard Vhosts as well as any SSL-enabled configurations can now be separated from the main file to avoid confusion.

The next article will look at configuring and optimizing Nginx for use on your Server.