Nginx Return 200 Without Download [best] Info

location /pixel { return 200 ''; add_header Content-Type text/plain; } Use code with caution. 3. Handling Global Health Checks

location /api/status { return 200 '{"status":"success","message":"processed"}'; add_header Content-Type application/json; } Use code with caution. 2. Empty 200 OK (The "Silent" Response)

Browsers are designed to protect users. If Nginx sends a status code (like 200) with a body but no instructions on how to handle that body, the browser assumes it is a file. nginx return 200 without download

Without a Content-Type , the browser "sniffs" the data. If it’s just a short string, it often fails and defaults to a download. Common Use Cases and Configurations 1. Returning JSON Data

If default_type in your nginx.conf is set to application/octet-stream , the browser will almost always download the response. location /pixel { return 200 ''; add_header Content-Type

Always run nginx -t before reloading. This checks your syntax to ensure your new headers don't crash your web server. If you'd like, I can help you: Write a configuration for a Set up conditional returns based on IP address Debug why a specific browser is still downloading the file

Ensure add_header is placed before the return statement in some older versions of Nginx, though modern versions handle it well within the same block. 💡 Pro-Tip Without a Content-Type , the browser "sniffs" the data

location = /health { access_log off; add_header Content-Type text/plain; return 200 'OK'; } Use code with caution. Troubleshooting Tips