map $http_user_agent $format_suffix { "~*curl" ".txt"; "~*wget" ".txt"; default ""; } # Also check for Accept: text/plain map $http_accept $final_suffix { "~*text/plain" ".txt"; default $format_suffix; } server { listen 80; server_name jayrup.me; root /usr/share/nginx/html; location / { # This handles: # 1. /cv -> /cv.txt (for curl) # 2. /cv -> /cv.html (for browser) # 3. /projects/ -> /projects/index.txt (for curl) try_files $uri$final_suffix $uri.html $uri/index$final_suffix $uri/index.html =404; } # Ensure text files are served correctly location ~* \.txt$ { add_header Content-Type text/plain; } }