Difference between revisions of "Create default website in nginx"

From DevOps Notebook
(Created page with "Default website in nginx is useful to close connection when someone tries to access to webserver via IP<br> which is shown in this example, but you can easily create redirect...")
 
 
Line 1: Line 1:
 
Default website in nginx is useful to close connection when someone tries to access to webserver via IP<br>
 
Default website in nginx is useful to close connection when someone tries to access to webserver via IP<br>
 
which is shown in this example, but you can easily create redirect to real website or have custom page.
 
which is shown in this example, but you can easily create redirect to real website or have custom page.
 
+
<syntaxhighlight lang="nginx">
 
server {
 
server {
 
     listen 80 default_server;
 
     listen 80 default_server;
Line 15: Line 15:
 
     }
 
     }
 
}
 
}
 +
</syntaxhighlight>

Latest revision as of 19:05, 8 October 2020

Default website in nginx is useful to close connection when someone tries to access to webserver via IP
which is shown in this example, but you can easily create redirect to real website or have custom page.

server {
    listen 80 default_server;
    server_name _; # This is invalid value which will match any host
    access_log /var/log/nginx/default.access.log;
    error_log /var/log/nginx/default.error.log;
    server_name_in_redirect off;

    root  /var/www/html;

    location ^~ / {
       return 444; # to close connection
    }
}