Nginx remove all /amp/ URLs with HTTP/301 redirect in bulk

I disabled AMP support in our app. So URL like example.com/foo/amp/ ends up with HTTP/404. How do I tell the Nginx to redirect example.com/foo/amp/ to example.com/foo/ and example.com/bar/amp/ to example.com/bar/. I want to rewrite the URL containing /amp/ to remove amp/ from the end with Nginx. Please guide.

The syntax is to rewrite the URL containing /amp/ to remove amp/ from the end using regex as follows:

rewrite regex URL [flag];

For example:

rewrite ^/foo/amp/$ /foo/ permanent;
rewrite ^/bar/amp/$ /bar/ permanent;
....
......
.......

Nginx remove all /amp/ URLs with HTTP/301 redirect in bulk

So let us turn that into the regex to match URLs:

rewrite ^(.*/)amp/$ $1 permanent;

Save and close the file. Test Nginx config from the Linux or Unix CLI. For example, as the root user:

nginx -t

If there are no errors, reload the nginx server:

nginx -s reload

Test it:

Use the curl CLI:

curl -IL https://example.com/foo/amp/
curl -IL https://example.com/bar/amp/