sandeep krishna
sandeep krishna

Reputation: 475

configure nginx to return 503 error code for all page except home page

One of my client is suspending the site for few months, so I am planning to set a landing page for the home page and return a 503 status code to all other links. (I read that returning 503 status code wont harm the seo )

How can this be possible via nginx config?

i have the following nginx config with me but it throw 503 for all request.

server {
    listen       80;
    listen  [::]:80;
    server_name  localhost;
    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;
    location / {
    return 503;
   }
 }

is it possible to configure nginx config to serve an index.html page at the doc root /usr/share/nginx/html and retrun 503 on all other link? what will be the nginx conf then?

Upvotes: 0

Views: 2737

Answers (1)

Ivan Shatsky
Ivan Shatsky

Reputation: 15547

Use the exact match location:

location = / {
    root /usr/share/nginx/html;
    index index.html;
}
# all the other requests will be served with the following location
location / {
    return 503;
}

Upvotes: 0

Related Questions