Select Page


On Ubuntu, the Nginx web server retail outlets its paperwork in /var/www/html, which is usually situated at the root filesystem with remainder of the running gadget. Now and again, despite the fact that, it’s useful to transport the record root to some other location, corresponding to a separate fastened filesystem. For instance, should you serve a couple of internet sites from the similar Nginx example, hanging every website’s record root by itself quantity lets you scale in line with the desires of a selected website or shopper.

On this information, you’ll transfer an Nginx record root to a brand new location.

Must haves

To finish this information, you’ll want:

We can use the area title on this instructional, however you must replace this with your personal area title.

  • A brand new location in your record root. On this instructional, we will be able to use the /mnt/volume-nyc3-01 listing for our new location. If you’re the use of Block Garage on DigitalOcean, this guide will display you the right way to create and fix your quantity. Your new record root location is configurable in response to your wishes, then again. If you’re transferring your record root to another garage software, it would be best to make a choice a location beneath the software’s mount level.

Step 1 — Copying Recordsdata to the New Location

On a recent set up of Nginx, the record root is situated at /var/www/html. By way of following the prerequisite guides, then again, you created a brand new record root, /var/www/ You’ll have further record roots as neatly. On this step, we will be able to identify the positioning of our record roots and duplicate the related information to their new location.

You’ll be able to seek for the positioning of your record roots the use of grep. Let’s seek within the /and so forth/nginx/sites-enabled listing to restrict our focal point to lively websites. The -R flag guarantees that grep will print each the road with the root directive and the overall filename in its output:

  • grep -R "root" /and so forth/nginx/sites-enabled

If you happen to adopted the prerequisite tutorials on a recent server, the outcome will appear to be this:


/and so forth/nginx/sites-enabled/ root /var/www/; /and so forth/nginx/sites-enabled/default: root /var/www/html; /and so forth/nginx/sites-enabled/default: # deny get admission to to .htaccess information, if Apache's record root /and so forth/nginx/sites-enabled/default:# root /var/www/;

When you’ve got pre-existing setups, your effects might fluctuate from what is proven right here. In both case, you’ll be able to use the comments from grep to be sure you’re transferring the specified information and updating the precise configuration information.

Now that you have showed the positioning of your record root, you’ll be able to reproduction the information to their new location with rsync. The use of the -a flag preserves the permissions and different listing homes, whilst -v supplies verbose output so you’ll be able to practice the development of the sync:

Be aware: Be certain there is not any trailing slash at the listing, that may be added should you use tab of entirety. When there’s a trailing slash, rsync will sell off the contents of the listing into the mount level as a substitute of shifting it right into a containing html listing.

  • sudo rsync -av /var/www/ /mnt/volume-nyc3-01

You’re going to see output like the next:


sending incremental report checklist created listing /mnt/volume-nyc3-01 html/ html/index.html despatched 318 bytes won 39 bytes 714.00 bytes/sec overall dimension is 176 speedup is 0.49

With our information in position, let’s transfer directly to editing our Nginx configuration to mirror those adjustments.

Step 2 — Updating the Configuration Recordsdata

Nginx uses each international and site-specific configuration information. For background concerning the hierarchy of configuration information, check out “How To Configure The Nginx Web Server On a Virtual Private Server”. We can adjust the server block file for our project: /and so forth/nginx/sites-enabled/

Be aware: Needless to say for your case will probably be your_domain_name, and that you’re going to be editing the server block information that had been outputted whilst you ran the grep command in Step 1.

Get started through opening /and so forth/nginx/sites-enabled/ in an editor:

  • sudo nano /and so forth/nginx/sites-enabled/

To find the road that starts with root and replace it with the brand new root location. In our case this will probably be /mnt/volume-nyc3-01/html:

/and so forth/nginx/sites-enabled/

server {

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

Stay a watch out for another puts that you just see the unique record root trail outputted through grep in Step 1, together with in aliases or rewrites. You’re going to additionally wish to replace those to mirror the brand new record root location.

While you’ve made all the important adjustments, save and shut the report.

Step 3 — Restarting Nginx

When you’ve completed making the configuration adjustments, you’ll be able to restart Nginx and take a look at the effects.

First, be certain that the syntax is right kind:

If the entirety is so as, it must go back:


nginx: the configuration report /and so forth/nginx/nginx.conf syntax is fine nginx: configuration report /and so forth/nginx/nginx.conf take a look at is a hit

If the take a look at fails, observe down and connect the issues.

As soon as the take a look at passes, restart Nginx:

  • sudo systemctl restart nginx

When the server has restarted, seek advice from your affected websites and make sure they’re running as anticipated. When you’re at ease that the entirety is so as, don’t omit to take away the unique reproduction of the information:

  • sudo rm -Rf /var/www/

You could have now effectively moved your Nginx record root to a brand new location.


On this instructional, we lined the right way to trade the Nginx record root to a brand new location. This allow you to with elementary internet server management, like successfully managing a couple of websites on a unmarried server. It additionally lets you make the most of selection garage units corresponding to community block garage, which will also be useful in scaling a internet website as its wishes trade.

If you happen to’re managing a hectic or rising internet website, you could be all for finding out how to set up Nginx with HTTP/2 to make the most of its prime switch pace for content material. You’ll be able to additionally be informed extra about making improvements to the manufacturing enjoy on this comparability of five ways to improve your production web application server setup.