3.6 KiB
3.6 KiB
Nginx Reverse Proxy Configuration
Overview
This Nginx configuration serves two main purposes:
- Static file listing from
/srv/files/under the/nginx-files/path. - Reverse proxy to MinIO running on
http://127.0.0.1:9001for all other requests.
The configuration also sets headers to ensure proper client information forwarding, support for WebSockets, and correct host resolution.
Server Block
server {
listen 80;
server_name files.usethelinux.shop;
error_log /var/log/nginx/file-error.log warn;
access_log /var/log/nginx/file-access.log;
- listen 80; — The server listens on HTTP port 80.
- server_name files.usethelinux.shop; — Responds to requests for this domain.
- error_log and access_log — Define custom log files for debugging and access tracking.
Location /nginx-files/ — Static File Listing
location /nginx-files/ {
alias /srv/files/;
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
}
- alias /srv/files/; — Maps the URL path
/nginx-files/to the filesystem path/srv/files/. - autoindex on; — Enables directory listing.
- autoindex_exact_size off; — Shows file sizes in human-readable format instead of exact bytes.
- autoindex_localtime on; — Displays file modification times in the server’s local timezone.
Location / — MinIO Reverse Proxy
location / {
proxy_pass http://127.0.0.1:9001;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
proxy_pass
- proxy_pass http://127.0.0.1:9001; — Forwards all requests to the MinIO server running on localhost port 9001.
proxy_http_version
- proxy_http_version 1.1; — Ensures the proxy uses HTTP/1.1, required for WebSocket support and persistent connections.
proxy_set_header
-
Upgrade $http_upgrade;
- Passes the
Upgradeheader from the client, needed for WebSocket connections. - Allows MinIO (or any WebSocket-enabled service) to handle protocol upgrades properly.
- Passes the
-
Connection "upgrade";
- Indicates that the connection may be upgraded (e.g., to WebSocket).
- Works with the
Upgradeheader to maintain persistent connections.
-
Host $host;
- Sends the original
Hostheader from the client to the upstream server. - Ensures that MinIO knows which hostname was requested and can generate correct URLs.
- Sends the original
-
X-Real-IP $remote_addr;
- Forwards the client’s IP address to the upstream server.
- Useful for logging, rate limiting, and IP-based access control.
-
X-Forwarded-For $proxy_add_x_forwarded_for;
- Maintains a list of all IP addresses the request has passed through (client → proxy → upstream).
- Helps upstream services identify the original client IP when multiple proxies are involved.
-
X-Forwarded-Proto $scheme;
- Passes the original protocol (
httporhttps) used by the client. - Important for generating correct links, redirects, or enforcing HTTPS in the upstream service.
- Passes the original protocol (
Summary
This configuration ensures:
- Efficient serving of static files with directory listing.
- Proper reverse proxying to MinIO with support for WebSockets.
- Accurate client information forwarding for logging and security.
- Compatibility with applications that depend on the original
Hostand protocol.