0

I'm trying to configure nginx to return a http 410 ("Resource Gone") code for any path under /

My config is below.

With this config, if I request /410test, I get a standard nginx 404 Not Found page, and a response status code of 404. So I'm having trouble even getting a response of 410 for one specific path, much less, all paths.

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
    worker_connections 768;
    # multi_accept on;
}

http {
    server {
        location /410test {
                return 410 "this is my 410 test page";
        }

    }


    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    gzip on;

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}
0

You are missing the listen directive from the server block in your config. You are getting 404s from your sites defined under conf.d & sites-enabled.

0

Put return directly in the server context:

http {
    server {
        return 410 "this is my 410 test page";
    }
}

Why it doesn't work with your config, is maybe because you're trying to access /410test/ (with trailing slash) which doesn't match your defined location.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.