<p>I am running celery flower on port inside Kubernetes with nginx-ingress controller</p>
<p>I want to do a rewrite where requests to /flower/(.*) request goes to /$1 according to their documentation:
<a href="https://flower.readthedocs.io/en/latest/config.html?highlight=nginx#url-prefix" rel="nofollow noreferrer">https://flower.readthedocs.io/en/latest/config.html?highlight=nginx#url-prefix</a></p>
<pre><code>server {
    listen 80;
    server_name example.com;

    location /flower/ {
        rewrite ^/flower/(.*)$ /$1 break;
        proxy_pass http://example.com:5555;
        proxy_set_header Host $host;
    }

}
</code></pre>
<p>I have come up with the following ingress.yaml</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: backend-airflow-ingress
  namespace: edna
  annotations:
    kubernetes.io/ingress.class: &quot;nginx&quot;
    nginx.ingress.kubernetes.io/use-regex: &quot;true&quot;
    ingress.kubernetes.io/rewrite-target: /$2
    # nginx.ingress.kubernetes.io/app-root: /flower
spec:
  rules:
  - host:
    http:
      paths:
      - path: /flower(/|$)(.*)
        backend:
          serviceName: airflow-flower-service
          servicePort: 5555
</code></pre>
<p>Inside POD running flower, I successfully get</p>
<pre class="lang-sh prettyprint-override"><code>curl localhost:5555/dashboard
</code></pre>
<p>However if get into the POD running Nginx controller, then it fails.</p>
<pre><code>curl localhost/flower/dashboard
</code></pre>
<p>I get response by the flower:</p>
<pre class="lang-html prettyprint-override"><code>&lt;div class=&quot;span12&quot;&gt;
&lt;p&gt;

Error, page not found

&lt;/p&gt;
&lt;/div&gt;
</code></pre>
<p>this is what I see inside nginx.conf in nginx-controller pod</p>
<pre><code>server {                                                                                                                                                           
                server_name _ ;                                                                                                                                            
                                                                                                                                                                           
                listen 80 default_server reuseport backlog=511 ;                                                                                                           
                listen 443 default_server reuseport backlog=511 ssl http2 ;                                                                                                
                                                                                                                                                                           
                set $proxy_upstream_name &quot;-&quot;;                                                                                                                              
                                                                                                                                                                           
                ssl_certificate_by_lua_block {                                                                                                                             
                        certificate.call()                                                                                                                                 
                }                                                                                                                                                          
                                                                                                                                                                           
                location ~* &quot;^/flower(/|$)(.*)&quot; {                                                                                                                          
                                                                                                                                                                           
                        set $namespace      &quot;edna&quot;;                                                                                                                        
                        set $ingress_name   &quot;backend-airflow-ingress&quot;;                                                                                                     
                        set $service_name   &quot;&quot;;                                                                                                                            
                        set $service_port   &quot;&quot;;                                                                                                                            
                set $location_path  &quot;/flower(/|${literal_dollar})(.*)&quot;;                                                                                                    
                                                                                                                                                                           
                        rewrite_by_lua_block {                                                                                                                             
                                lua_ingress.rewrite({                                                                                                                      
                                        force_ssl_redirect = false,                                                                                                        
                                        ssl_redirect = true,                                                                                                               
                                        force_no_ssl_redirect = false,                                                                                                     
                                        use_port_in_redirects = false,                                                                                                     
                                })                                                                                                                                         
                                balancer.rewrite()                                                                                                                         
                                plugins.run()                                                                                                                              
                        }                                                                                                                                                  
                                                                                                                                                                           
                        # be careful with `access_by_lua_block` and `satisfy any` directives as satisfy any                                                                
                        # will always succeed when there's `access_by_lua_block` that does not have any lua code doing `ngx.exit(ngx.DECLINED)`                            
                        # other authentication method such as basic auth or external auth useless - all requests will be allowed.                                          
                        #access_by_lua_block {                                                                                                                             
                        #}                                                                                                                                                 
                                                                                                                                                                           
                        header_filter_by_lua_block {                                                                                                                       
                                lua_ingress.header()                                                                                                                       
                                plugins.run()                                                                                                                              
                        }                                                                                                                                                  
                                                                                                                                                                           
                        body_filter_by_lua_block {                                                                                                                         
                        }             
</code></pre>

<p><strong>Ok figured this out</strong></p>
<pre><code>ingress.kubernetes.io/rewrite-target: /$2
</code></pre>
<p>should be in my case a different annotation</p>
<pre><code>nginx.ingress.kubernetes.io/rewrite-target: /$2
</code></pre>
