Nginx container always gives 404

2/15/2018

Please look at below nginx.conf content which is present in my azure aks:

server {
    listen 80 default_server;
    listen 443 ssl default_server;

    ssl_certificate /etc/nginx/secrets/default;
    ssl_certificate_key /etc/nginx/secrets/default;

    server_name _;
    server_tokens "on";
    access_log off;



    location / {
       return 404;
    }
}

include /etc/nginx/conf.d/*.conf;

looking at the above content i figured out that my ingress contents are present in conf.d folder.

If we see, location / is present before my other configurations. does that mean it is always returning 404 because of this reason?

-- Anil Kumar P
azure
docker
kubernetes
nginx

1 Answer

2/15/2018

The location setting lets you configure how nginx will respond to requests for resources within the server.

You can have more than one location directive.

Request: http://example.com/

Returns: Assuming that there is a server_name entry for example.com, the location / directive will determine what happens with this request. In your case, it will return 404. And since every request can map to location /, nginx will always respond with 404.

Refer https://linode.com/docs/web-servers/nginx/how-to-configure-nginx/#location-file-and-folder-configuration for more info.

What you have here is the conf for default backend. The default backend is a service which handles all url paths. It returns a 404 when the Ingress Controller cannot successfully route a request according to the mapping rules.

location / being present before (as in the order of occurrences) other configurations is not the problem here.

The default-http-backend is not designed to be outside facing -- it is merely designed to 404 so the Ingress controller can universally /dev/null traffic for Pod-less Services.

Please refer: https://docs.microsoft.com/fi-fi/azure/aks/kubernetes-walkthrough

-- RKalra
Source: StackOverflow