0

How do I setup 410 permanently deleted on nginx for a specific URL for e.g.

https://www.example.com/product/somepage.html

Or better yet how can I do it for a specific prefix for e.g.

https://www.example.com/product/

Here I want to 410 all URLs that are /product/ for e.g. /product/page1.html, /product/page2.html etc.

Here's my current conf setup.

server {
        listen 80;
        listen [::]:80;
        server_name example.com;
        return 301 https://www.example.com$request_uri;
}


server {
        listen 80;
        listen [::]:80;
        root /var/www/example.com/html;
        index portal.php index.php  index.html index.htm;

        server_name www.example.com;

        location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
          expires 1M;
          add_header Cache-Control public;
          add_header Pragma public;
        }

        location ~ ^/\.user\.ini {
                deny all;
        }
        
        #some more config here
}
Frank Martin
  • 741
  • 2
  • 12
  • 24

1 Answers1

2

Use a return statement to generate the required status response.

A location statement with the ^~ operator is probably best as it cannot be overridden by other regular expression locations.

For example:

location ^~ /product/ { 
    return 410; 
}
Richard Smith
  • 12,834
  • 2
  • 21
  • 29