Skip to content

Instantly share code, notes, and snippets.

@gautamchitnis
Created May 15, 2021 21:10
Show Gist options
  • Save gautamchitnis/629a6d5f52bc077688b7f6f83da10b1e to your computer and use it in GitHub Desktop.
Save gautamchitnis/629a6d5f52bc077688b7f6f83da10b1e to your computer and use it in GitHub Desktop.
Nginx Serve Static Files from /root

NOTE: It is not advisable to do this, use /var/www/ or similar directories to store your static files.

Okay, now if you must keep your files in /root then follow along.

Consider the static files are in /root/site/static/ path.

  1. Run sudo chmod -R 0755 /root
  2. Run sudo chmod -R 0755 /root/site
  3. Run sudo chown -R "$USER":www-data /root/site (replace www-data with the username of your nginx user with whatever user is used in nginx.conf usually located at /etc/nginx)
  4. Restart Nginx, now your static files should be accessible.
  5. Use namei -l /root/site/static/somefile to check if necessary permissions are set in case of issues.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment