1.6 KiB
1.6 KiB
📄 NGINX File Server Configuration
This configuration sets up an NGINX server to serve files from two different directories:
/srv/filesfor general file browsing at the root path (/)/srv/imagesfor image browsing at/image
server {
# Define the domain name for this server block
server_name domain;
# Default root directory for the server
root /srv/files;
# Serve files and list directory contents at the root URL (e.g., http://domain/)
location / {
autoindex on; # Enables directory listing
}
# Serve images and list contents at /image (e.g., http://domain/image/)
location /image {
autoindex on; # Enables directory listing
root /srv/images; # Note: this overrides the global root
# Final path served will be /srv/images/image/ due to how root works
}
}
⚠️ Important Notes
-
Path Behavior:
-
In the
/imageblock, usingrootadds the location path (/image) to the end. Sohttp://domain/image/will map to/srv/images/image/. -
If you want
/image/to map directly to/srv/images/, usealiasinstead:location /image/ { autoindex on; alias /srv/images/; }
-
-
Security:
- Be cautious when enabling
autoindex; it exposes directory contents to the public. - Consider restricting access or adding authentication for sensitive directories.
- Be cautious when enabling
-
Permissions:
- Ensure the NGINX user (usually
www-data) has read access to the directories.
- Ensure the NGINX user (usually