Set Up a Simple File Server on Linux with Nginx
Setup and Configuration
Install Nginx
Ensure the Nginx web server package is installed on your Linux distribution.
Debian/Ubuntu-based systems
1 | sudo apt update |
RHEL/CentOS/Fedora-based systems
Early systems
1 | sudo yum install nginx |
Latest systems
1 | sudo dnf install nginx |
Create the Shared Directory
Define the directory you intend to share via Nginx. Using a path outside of the default web root (/var/www/html) is often cleaner.
This is an example to create a folder at /srv/file_share.
1 | sudo mkdir -p /srv/file_share |
Configure Nginx
We will create a specific configuration file in the /etc/nginx/conf.d/ directory. This is often the simplest method, as modern Nginx installations are pre-configured to automatically include files from this location.
Create the file and name it appropriately (e.g., file_server.conf):
1 | sudo vim /etc/nginx/conf.d/file_server.conf |
Paste the following server block configuration. We will use port 10000 to avoid conflicts. Remember to replace your_server_ip_or_domain with your own setting.
1 | server { |
Test and Restart
Test the configuration syntax
1 | sudo nginx -t |
Ensure the output confirms: syntax is ok and test is successful.
Restart the Nginx service
1 | sudo systemctl restart nginx |
Troubleshooting
If you cannot access your file server at http://your_server_ip:10000/, it is almost certainly due to one of the following reasons.
Firewall Configuration
If the web server is running but the page times out or refuses connection, your firewall is likely blocking port 10000.
Option A: Open the Specific Port (Recommended)
1 | sudo ufw allow 10000/tcp |
Option B: Disable the Firewall (For Testing Only)
To quickly confirm that the firewall is the issue, you can temporarily disable UFW. Do not leave the firewall disabled on production servers.
1 | sudo ufw disable |
Nginx Main Configuration Check
While placing files in conf.d/ is generally correct, it only works if the main Nginx configuration file is set to include them.
Check the main config file
1
sudo vim /etc/nginx/nginx.conf
Verify the include directive
Inside the main
http { ... }block, ensure one of the following lines exists:1
2
3
4
5
6http{
# ...other settings...
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
Linux File Permissions Fix (The 403 Solution)
If the Nginx configuration is correct, a 403 Forbidden is almost always a Linux file permission issue.
Check the Nginx Error Log (The Crucial First Step) 🔍 This log will definitively tell you why Nginx is blocking the request. Look for
Permission denied(a file system issue) ordirectory index is forbidden(a missingautoindex on;directive).1
sudo tail /var/log/nginx/error.log
Identify the Nginx User: Confirm the user Nginx is running as.
1
grep "user" /etc/nginx/nginx.conf
If it returns
user www-data;oruser nginx;, it means Nginx doesn't have enough permission to access thefile_sharefolder.Fix Ownership and Permissions: If the log showed
(13: Permission denied), Nginx cannot read your files. Replace/srv/file_sharewith your actual path, and replacewww-datawith your Nginx user if necessary.Option 1: Change ownership to the Nginx user
1
sudo chown -R www-data:www-data /srv/fileserver/
Option 2: Set Directory Permissions (755): Read/Execute for all
1
sudo find /srv/file_share/ -type d -exec chmod 755 {} \;
Option 3: Set File Permissions (644): Read-only for Nginx
1
sudo find /srv/file_share/ -type f -exec chmod 644 {} \;
Fix Home Directory Path Permissions (If Applicable): If your files are in a home folder (e.g.,
/home/ubuntu/file_share), you must allow the Nginx user to traverse the parent directory. Replaceubuntuwith your username.1
sudo chmod o+x /home/ubuntu/
Complete All Steps and Restart
After making any changes to permissions, configurations, or the firewall, always test the configuration and restart the service one final time.
1 | sudo nginx -t |
Your file server should now be fully accessible!
- Title: Set Up a Simple File Server on Linux with Nginx
- Author: Fireflies
- Created at : 2025-05-24 14:31:09
- Updated at : 2026-04-02 08:44:38
- Link: https://fireflies3072.github.io/file-server/
- License: This work is licensed under CC BY-NC-SA 4.0.