Question
Setting up nginx on the Dokku droplet to show 404 errors
Building on top of the question here:
https://www.digitalocean.com/community/questions/dokku-and-preventing-random-domains
I figured out how to have a landing page for my main host as well as still serve my vhosts, e.g.
example.com -> index.html
app1.example.com -> app1
Those two things work OK, but I’m curious about how to setup a 404 page for invalid vhosts, e.g.
NonExistentApp.eample.com -> 404
instead of
NonExistentApp.example.com -> example.com
The location
section of my /etc/nginx/sites-enabled/default does look like its supposed to serve a 404 if it cant find what the URL is requesting, but I think there’s some issue where it still tries to serve the main index.html, even if there’s an invalid vhost
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
Any help would be appreciated!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
×