0

when I configure nginx to redirect /monitor to opensearch, opensearch receives the requests and redirects the user to /app/something which is not under /monitor and thus fails (error 404).

My nginx config is

upstream opensearch {
    server 172.20.0.3:5601;
}

server {
    listen 443 ssl;
    server_name maindomain;
    server_tokens off;
    #access_log off;
    error_log  /var/log/nginx/cii.error_log  debug;
    access_log  /var/log/nginx/cii.error_log;


    ssl_certificate /etc/letsencrypt/live/mydomain/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/mydomain/privkey.pem;

    include /var/ssl/options-ssl-nginx.conf;
    ssl_dhparam /var/ssl/dhparam.pem;

    
    location ~ ^/monitor(/?)(.*) {
        

        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass_header User-Agent;
        proxy_pass http://opensearch/$2;
    }
    #put the / location AT THE END
    location / {
        root /usr/share/nginx/html;
    }    
}

Any ideas how I can configure nginx (or Opensearch?) to continue using /monitor/app/something ?

mojovski
  • 113
  • 5
  • Does this answer your question? [Nginx reverse proxy + URL rewrite](https://serverfault.com/questions/379675/nginx-reverse-proxy-url-rewrite) – djdomi Jun 27 '23 at 16:22
  • thanks. I don't think so. My problem is not that I can't access the opensearch upstream. The problem is that when opensearch redirects to /app, it should be /monitor/app. I guess I will have to code all the cases (app, ...) as location inside the nginx config for rewrite then – mojovski Jun 27 '23 at 16:48
  • each other path has to be set separate, nginx looks from top to down to find the right path inside the configuration – djdomi Jun 28 '23 at 17:22

0 Answers0