How to Install Virtualhost NGINX Server on CentOS 7

Add the Nginx repository to your server’s list of software sources
If you only need Nginx, you can install it through Nginx’s yum repository:

$ sudo rpm -Uvh

Download and install Nginx, you can use yum to download and install Nginx.

$ sudo yum install nginx

we need to make a directory structure that will hold the site data to serve to visitors:

sudo mkdir -p /var/www/
sudo mkdir -p /var/www/

change the ownership with chown:

sudo chown -R $USER:$USER /var/www/
sudo chown -R $USER:$USER /var/www/
sudo chmod -R 755 /var/www

create demo page on every directory:

nano /var/www/
nano /var/www/

example page:


create NGINX server configuration for virtual host:

sudo mkdir /etc/nginx/sites-available
sudo mkdir /etc/nginx/sites-enabled

include those directory in nginx.conf:

sudo nano /etc/nginx/nginx.conf

add these line:

include /etc/nginx/sites-enabled/*.conf;
server_names_hash_bucket_size 64;

create the vhost configuration:

sudo nano /etc/nginx/sites-available/


server {
    listen  80;


    location / {
        root  /var/www/;
        index  index.html index.htm;
        try_files $uri $uri/ =404;

    error_page  500 502 503 504  /50x.html;
    location = /50x.html {
        root  /usr/share/nginx/html;

enable those configuration:

sudo ln -s /etc/nginx/sites-available/yourdomain1.conf /etc/nginx/sites-enabled/yourdomain1.conf

restart your NGINX server:

sudo systemctl restart nginx

GREAT!!! you can test your results

Wagiman Wiryosukiro

Petani Sistem Informasi, tukang las plugin & themes Wordpress. Co-Founder Saat ini aktif sebagai Developer & kontributor di OpenMandriva Linux.

You may also like...

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: