• Contact
  • Contact Us
  • Disclamer
  • Home 1
  • Home 2
  • Home 3
  • Privacy Policy
Sunday, May 18, 2025
How VPS - How to use/setup VPS
  • Login
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
How VPS - How to use/setup VPS
No Result
View All Result
Home Control Panels

How To Move the Nginx Web Root to a New Location on Ubuntu 18.04

How VPS by How VPS
November 2, 2018
in Control Panels
0
0
SHARES
28
VIEWS
Share on FacebookShare on Twitter

Contents

  1. Introduction
  2. Prerequisites
  3. Step 1 – Transfering Files to Your New Location
  4. Step 2 – Updating Nginx Configuration Files
  5. Step 3  – Restarting Nginx
  6. Conclusion
  7. Check out these top 3 Linux hosting services
    1. Was this article helpful?

Introduction

Nginx is a powerful HTTP server designed to store documents in the directory /var/www/html (document root). This directory is found on a root filesystem with other operating system directories. Sometimes it’s important to transfer this document root (/var/www/html) to a different directory such as a separately mounted filesystem.

This comes in handy, primarily when you are serving numerous sites from one Nginx instance. By putting each document root on a different volume makes it easy to scale up with the growing needs of each website or client.

This tutorial will help you transfer the Nginx web root to another location.

Prerequisites

For this guide to follow flawlessly, you require the following:

  • Ubuntu 18.04 server
  • Nonroot user with sudo permissions
  • An SSL/TLS certificate setup for your Ubuntu 18.04 server.
  • Besides, this tutorial will make use of example.com as the domain name. Remember to substitute this domain with your unique domain name.
  • A new document root location. In our guide, we’ll utilize the directory /mnt/volume-nyc3-01, as the new location for the document root.

Step 1 – Transfering Files to Your New Location

When Nginx is installed and fully configured, /var/www/html serves as its default document location or document root. Our goal is to transfer this document root to another location /var/www/example.com/html. First, let us establish the exact location of the document roots, then transfer all the vital files to the new location.

We’ll use the grep command to see where the document roots are located. Execute the command below to search the location in the directory /etc/nginx/sites-enabled:

$ grep -R "root"/etc/nginx/sites-enabled

The command focuses the search on all the active sites. It includes an -R flag which enables grep to print both the full name and the line featuring a root directive. This will give you an output similar to the one below:

/etc/nginx/sites-enabled/example.com:           root /var/www/example.com/html;
/etc/nginx/sites-enabled/default:               root /var/www/html;
/etc/nginx/sites-enabled/default:               # deny access to .htaccess files, if Apache's document root
/etc/nginx/sites-enabled/default:#              root /var/www/example.com;

The output may differ depending on the pre-existing configurations. For this reason, it’s nice to utilize grep to ensure that you are moving right files to the new locations and that you are making changes to the desired configuration files.

Once you confirm the document root location, let use use the rsync to copy these files and move them to the new location.

$ sudo rsync -av /var/www/example.com/html /mnt/volume-nyc3-01

The command includes an -a flag which carries on the directory’s permissions and preserves other vital directory properties. On the other hand, the -v flag offers a verbose output to help you monitor the synchronization.

The output will be:

sending incremental file list
created directory /mnt/volume-nyc3-01
html/
html/index.html

sent 318 bytes  received 39 bytes  714.00 bytes/sec
total size is 176  speedup is 0.49

By now the files are in place, but we have to modify the Nginx configuration file to adapt the changes.

Step 2 – Updating Nginx Configuration Files

Nginx web server utilizes both site-specific and global configuration files. Here, we’ll modify the file /etc/nginx/sites-enabled/example.com; a block server file for the domain example.com.

Note: You should substitute example.com with your domain name.

First, execute the command below to open this file:

$ sudo nano /etc/nginx/sites-enabled/example.com

Once the file is opened, locate a line that starts with root. Now, update this line with the value of your new document root location. This tutorial, uses /mnt/volume-nyc3-01/html as the new location. You should have the following:

server {

        root /mnt/volume-nyc3-01/html;
        index index.html index.htm index.nginx-debian.html;
        . . .
}
. . .

Note: Take note of any other place featuring traces of the root path to the old document. Any root path, alias or rewrite that shows details of the original document file should be updated to feature the new location of your document root.

Once you make the required changes, save block server file and close it.

Step 3  – Restarting Nginx

We have successfully move the files and made changes to the Nginx configuration file. Next, we restart Nginx service for these changes to take effect.

First, run the command below to check the syntax:

$ sudo nginx -t

If all is okay, you should get the output below:

nginx: the configuration file /etc/nginx/nginx.confsyntax is ok
nginx: configuration file /etc/nginx/nginx.conftest is successful

In case this test fails, inspect the problem and fix it. Next, run the command below to restart your Nginx service:

$ sudo systemctl restart nginx

Once the service restarts, check all the sites affected by the web root trabsfer and make sure they are running correctly. If you are comfortable with the results, execute the command below to erase the original data copy:

$ sudo rm -Rf /var/www/example.com/html

That is it!

Conclusion

Congratulations! You have transferred the Nginx web root to another location, and it’s now easy to manage your web server.

Check out these top 3 Linux hosting services

0

Was this article helpful?

Submit
Previous Post

Mutt – A Command Line Email Client to Send Mails from Terminal

Next Post

5 Interesting Command Line Tips and Tricks in Linux – Part 1

Next Post

5 Interesting Command Line Tips and Tricks in Linux – Part 1

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

No Result
View All Result

Recent Post

Install Imagemagick on CentOS
CentOS

Install Imagemagick on CentOS

by How VPS
June 28, 2023
0

This is how I installed Imagemagick on a vanilla CentOS server Start off by installing the prerequisites yum install php-pear...

Read more
how to Check phpinfo

How to Check phpinfo of Hosting or VPS?

June 28, 2023
Failed to download metadata for repo 'appstream' on Centos 8

How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

February 25, 2022
How to Fix MySQL Error "Plugin 'InnoDB' registration as a STORAGE ENGINE failed"?

How to Fix MySQL Error “Plugin ‘InnoDB’ registration as a STORAGE ENGINE failed”?

November 17, 2020
How to optimize Mysql or MariaDB

How to optimize Mysql or MariaDB

November 3, 2020

Recent News

  • Install Imagemagick on CentOS
  • How to Check phpinfo of Hosting or VPS?
  • How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

Category

  • Arch
  • Authentication
  • Backups
  • BSD
  • Centmin Mod
  • CentOS
  • Control Panels
  • CoreOS
  • CWP
  • Debian
  • Directadmin
  • Encryption
  • Fedora
  • Firewalls
  • Hocvps Script
  • Hosting providers
  • Kloxo-MR
  • Linux
  • Mitigations
  • Operating System
  • Plesk
  • Reviews
  • Securing VPS/Servers
  • Security Patches
  • SSL Certificates
  • Uncategorized
  • Upgrading
  • VPS/Servers management guides
  • Vulnerability Detection
  • Web servers software
  • Webhosting Control Panel
  • About
  • Advertise
  • Careers
  • Contact

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In
Thabet