1
submitted 4 days ago* (last edited 4 days ago) by Rick_C137@programming.dev to c/webdev@programming.dev

Hi,

You might be aware that if a DNS request point your nginx server.

and this later do not have a server rule for it , nginx will server anyway the first server found in your config file, WTF !

So I've found https://stackoverflow.com/a/23281442

server {
  listen       80 default_server;
  server_name  everythingelse;

  error_page 404 /404.html;

  # Everything is a 404
  location / {
    return 404; #return the code 404
  }

  # link the code to the file
  location = /404.html {
    #EDIT this line to make it match the folder where there is your errors page
    #Dont forget to create 404.html in this folder
    root  /var/www/nginx/errors/;
  }
}

But this is not working !

I made one of my domain pointing to this nginx server, and he still server another site aka server For httpS for http nothing appear..

Thanks.

you are viewing a single comment's thread
view the rest of the comments
[-] Rick_C137@programming.dev 1 points 4 days ago

ok I've found something that ~works !

	server {
		listen 443 ssl;
		server_name _;
		ssl_certificate /etc/nginx/ssl/catchall.crt;
		ssl_certificate_key /etc/nginx/ssl/catchall.key;

		error_page 404 /404.html; #at /var/www/html/

		location /404.html {internal;}

		return 404;
	}

so i get the default 404 html from nginx. but not the one that I specified error_page 404 /404.html; any ideas ?

[-] Rick_C137@programming.dev 1 points 4 days ago

The full working code:

server {
    listen 443 ssl;
    server_name _;
    ssl_certificate /etc/nginx/ssl/catchall.crt;
    ssl_certificate_key /etc/nginx/ssl/catchall.key;

    error_page 404 /404_CatchAll.html;

    # Everything is a 404
    location / {
        return 404;
    }

    location /404_CatchAll.html {root /var/www/html/;}
}
this post was submitted on 28 Jun 2024
1 points (60.0% liked)

Web Development

3255 readers
15 users here now

Welcome to the web development community! This is a place to post, discuss, get help about, etc. anything related to web development

What is web development?

Web development is the process of creating websites or web applications

Rules/Guidelines

Related Communities

Wormhole

Some webdev blogsNot sure what to post in here? Want some web development related things to read?

Heres a couple blogs that have web development related content

CreditsIcon base by Delapouite under CC BY 3.0 with modifications to add a gradient

founded 1 year ago
MODERATORS