Skip to main content

Command Palette

Search for a command to run...

custom error page in nginx

Published
1 min read
custom error page in nginx
G

gua memang serious cakap lu, gua serious 24 jam. baik di jamban ,di meja makan atau bersenggama . serius...dohhh

first create an error page (error.html) in your root document.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Error</title>
    <style>
        body { text-align: center; font-family: Arial, sans-serif; }
        h1 { color: red; }
    </style>
</head>
<body>
    <h1>Error</h1>
    <p>Something went wrong. Please try again later.</p>
</body>
</html>

edit your nginx configuration file /etc/nginx/nginx.conf or /etc/nginx/site-available/default

server {
    listen 80;
    server_name yourdomain.com;

    root /var/www/html;
    index index.html index.htm;

    # Define custom error pages for multiple errors
    error_page 400 403 404 500 502 503 504 /error.html;

    # Prevent direct access to the error page
    location = /error.html {
        internal;
    }

    location / {
        try_files $uri $uri/ =404;
    }
}

restart your nginx

sudo systemctl restart nginx