Like the Apache2 UserDir module, Nginx can also be configured to do the same, albeit in a different way. In some school environments, you’ll see examples where teachers are given their website to publish materials for students to access. Instead of having to create multiple server blocks, the system administrator can use the UserDir feature to accomplish this. The URL to reach the teacher’s page is usually the domain name followed by /~teacher_name. User Directory or Userdir for short is a feature for the Nginx web server that allows user-specific directories to be accessed via Nginx.  For example, when you enable this feature in Nginx, users with accounts on the system will be able to share content in their home directories with the world via Nginx. This tutorial assumes that you already have an Nginx web server installed. If you haven’t, you may want to do that before continuing below.

Install Nginx HTTP Server

First, run the commands below to install Nginx HTTP Server on Ubuntu

Setup UserDir on Nginx

Unlike Apache2, there is no module to enable or installed. Nginx implementation is a bit different. To enable the Nginx Userdir feature, open the default website configuration file. or create a new one for the domain you want to have user share their directories. The commands below open the Nginx default site configuration file. Then add the highlighted block of code to the settings below:

Creating User Directories

Now that the feature is enabled, all users have to do is run the commands below to create a folder in their home directories called public_html by running the commands below. In the ~/public_html folder, create HTML documents to be shared and accessed via the web server. Restart the Nginx web server to load the settings. Now test it out by browsing to the server hostname or IP address followed by the username. example: http://example.com/~richard This is how the Nginx Userdir feature is configured for users to allow users with accounts on the systems to share content from their home directories. That’s it!