Preparing /var/www/html for Deployment and User Access

Introduction

After setting up our optimized Nginx web server, we need to configure the /var/www/html directory properly. This ensures that our user tm has the right permissions to manage website files without security risks.

Step 1: Creating the Necessary Directories

By default, Nginx serves content from /var/www/html, but we want to make sure it’s properly structured.

sudo mkdir -p /var/www/html

If you plan to serve multiple websites, you might want to create separate directories for each site:

sudo mkdir -p /var/www/example.com/html

Step 2: Assigning Ownership to the User tm

By default, files in /var/www/ may be owned by root, which isn’t ideal for ease of management. We will change the ownership to the user tm while keeping Nginx operational.

sudo chown -R tm:www-data /var/www/html

If you created a specific directory for a website:

sudo chown -R tm:www-data /var/www/example.com/html

This grants tm full control while keeping Nginx in the www-data group.

Step 3: Adjusting Permissions

To prevent unwanted modifications by other users, we set restrictive permissions:

sudo chmod -R 750 /var/www/html

This ensures that:

  • The owner (tm) has full access.
  • The www-data group (used by Nginx) can read and execute.
  • Other users have no access.

For individual website directories:

sudo chmod -R 750 /var/www/example.com/html

Step 4: Adding tm to the www-data Group

If tm needs to collaborate with other web-related services, adding them to the www-data group helps:

sudo usermod -aG www-data tm

Log out and back in for the changes to apply:

exit
ssh tm@your-server-ip

Conclusion

With these changes, tm now has proper access to manage website files securely, and Nginx can still serve them efficiently. In the next post, we’ll cover automated deployment and syncing website changes effortlessly. Stay tuned!