Thursday, December 6, 2018

Setup Userdir On Nginx

The commands below opens Nginx default site configuration file.

sudo nano /etc/nginx/sites-available/default

Then add the highlighted block of code the settings below:

# Default server configuration

server {
        listen 80 default_server;
        listen [::]:80 default_server;

        # SSL configuration
        # listen 443 ssl default_server;
        # listen [::]:443 ssl default_server;

        root /var/www/html;

        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html;
        server_name example.com www.example.com;

         location ~ ^/~(.+?)(/.*)?$ {
         alias /home/$1/public_html$2;
         index index.html index.htm;
         autoindex on;
           }

}
Creating User Directories
mkdir ~/public_html

In the ~/public_html folder, create html documents to be shared and accessed via the webserver.

Restart Nginx webserver to load the settings.
sudo systemctl restart nginx.service

Now test to open browsing followed by username :

example: http://example.com/~jagdeep

No comments:

Post a Comment