I'm trying to get Nginx to return a simple webpage, but always with an http status code of 403. For some reason, I just can't get it to work. I have two files in /var/www/html/:
- index.html
- photo.jpg
index.html displays some text along with photo.jpg
Here is my Nginx config:
server { listen 80 default_server; listen [::]:80 default_server; root /var/www/html; index index.html index.htm index.nginx-debian.html; server_name _; location / { return 403; } error_page 404 /index.html; error_page 403 /index.html; location = /index.html { allow all; } location = /photo.jpg { allow all; } }
With this config as-is, both index.html and photo.jpg are displayed with a status of 200. If I remove the location
blocks for those two files, neither are displayed, but they have a status of 403. My question is: How can I display the html file, along with the image, but just return a status of 403? I feel like I'm missing something simple.
return 403 <url>;
orreturn 403 "some text with newline at the end";
. nginx.org/en/docs/http/ngx_http_rewrite_module.html#return But I haven't tested it personally.