ELK -- kibana cannot be accessed after using nginx proxy

background:

        After setting up elk locally, everything was normal. Later, I changed to use nginx to proxy kibana port 5601. I found that it could not be accessed normally after proxying (the unproxyed address could be accessed normally). I spent a lot of time checking the problem. The errors reported were basically http : //ip:port/spaces/enter , or a 404 level error, or the / symbol is missing. I have tried it, but it still doesn’t work. As long as you want to change its access address, an error will be reported.

The proxy configuration is as follows:

	server {
        listen       6667; 
		server_name  localhost;
		location /kibana/ {
            proxy_pass http://192.168.0.111:5601/;
        }
    } 

reason:

        The request address http://ip:port/spaces/enter after proxy cannot be mapped normally.

As a result, the kibana server address http://192.168.0.111:5601/spaces/enter cannot be accessed.

        After solving the problem, I found that the page access of kibana should involve a redirect callback.

For example, your server access address is http://192.168.0.111:5601/app/XXX, 

After you proxy the port and uri, the access becomes http://ip:6667/kibana/app/XXX.

After mapping, the address is http://192.168.0.111:5601/app/XXX.

        The problem is that kibana redirects, and when he calls back internally,

The proxy calling address is http://ip:6667/spaces/enter,

If you press this address, the nginx configuration above cannot be mapped to http://192.168.0.111:5601/spaces/enter normally.

Even if you add the address http://ip:6667/spaces/enter to be mapped to the server, there may be other callback uri addresses that need to be processed.

solve:

        1: Only proxy the port, not the uri. This is equivalent to replacing 5601 with another port.

	server {
        listen       6667; 
		server_name  localhost;
		location / {
            proxy_pass http://192.168.0.111:5601/;
        }
    } 

        Processing results can be accessed normally

        2: Proxy port and uri (if you only proxy the port, you don’t need to use nginx, just modify the port directly in the kibana configuration file). Add a base path to kibana. This base path is the same as the agent's path/kibana.

(That is, the server adds /kibana in front of the access uri path. The original service address http://192.168.0.111:5601/app becomes http://192.168.0.111:5601/kibana/app)

        Go to the config directory of kibana's configuration file, modify kibana.xml, and add configuration

server.basePath: "/kibana"
server.rewriteBasePath: true

like:

After accessing the proxy, enter the login page with the address http://ip:6667/kibana/app. According to the mapping rules below, the address is mapped to http://192.168.0.111:5601/kibana/app (equivalent to when the kibana server does not add a basic path. http://192.168.0.111:5601/app)

Agent callback address http://ip:6667/kibana/spaces/enter (the details can be mapped to the server normally)

The mapped address is http://192.168.0.111:5601/kibana/spaces/enter (equivalent to http://192.168.0.111:5601/spaces/enter when the kibana server does not add a basic path)

    server {
        listen       6667; 
 
		location /kibana/ {
            proxy_pass http://192.168.0.111:5601/kibana/;
        }
    } 

        Processing results can be accessed normally

        In fact, you can also route all possible redirect URIs back to kibana in nginx, so that kibana can not add the basic path, but I don’t know the specific addresses, so I won’t do this solution.

The above is my solution to the problem that the nginx proxy cannot be accessed normally. The redirect above is my guess, and it may not be true. If anyone has doubts, please give me some advice.

Guess you like

Origin blog.csdn.net/DGH2430284817/article/details/130563795