<p>I have trouble about nginx ingress using condition</p>

<p>Install Nginx Ingress via helm instal (tested in both nginx-ingress-1.16 and nginx-ingress-1.36</p>

<p>I am try to follow 
<a href="https://stackoverflow.com/questions/59230411/ingress-nginx-redirect-from-www-to-https">ingress nginx redirect from www to https</a>
Setup some condition  </p>

<p>like</p>

<pre><code>    nginx.ingress.kubernetes.io/configuration-snippet: |
      if ( $host = "mydomain.co" ) {
        rewrite ^ https://www.mydomain.co$uri permanent;
      }
</code></pre>

<p>When apply the ingress rule, nginx ingress start reload in fail status</p>

<pre><code>-------------------------------------------------------------------------------
W0602 07:35:36.244415       6 queue.go:130] requeuing vincent/demoheader-ingress, err
-------------------------------------------------------------------------------
Error: exit status 1
2020/06/02 07:35:36 [notice] 982#982: ModSecurity-nginx v1.0.0
2020/06/02 07:35:36 [emerg] 982#982: invalid condition "~" in /tmp/nginx-cfg971999838:530
nginx: [emerg] invalid condition "~" in /tmp/nginx-cfg971999838:530
nginx: configuration file /tmp/nginx-cfg971999838 test failed

</code></pre>

<p>My Full ingress rule</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: demoheader-ingress
  namespace: namespace
  annotations:
    kubernetes.io/ingress.class: nginx-temp
    nginx.ingress.kubernetes.io/force-ssl-redirect: "true"
    nginx.ingress.kubernetes.io/from-to-www-redirect: "true"
    nginx.ingress.kubernetes.io/configuration-snippet: |
        if ( $uri ~* ^/xx/(.*) ) {
          rewrite ^ https://www.xxx.co permanent;
        }
spec:
  rules:
  - host: mydomain
    http:
      paths:
      - backend:
          serviceName: header-headerv1
          servicePort: 80
        path: /
EOF
</code></pre>

<p>Any idea ?</p>

Vincent Ngai
<p>OK i know what happen in here</p>

<p>I encount a wired issue for k8s apply stuff ….
While official document  told you , you can apply object by this method</p>

<pre><code>cat &lt;&lt;EOF | kubectl apply -f - 
xxx
yyy
eee
EOF
</code></pre>

<p><a href="https://kubernetes.io/docs/reference/kubectl/cheatsheet/" rel="nofollow noreferrer">https://kubernetes.io/docs/reference/kubectl/cheatsheet/</a></p>

<p>However for ingress rule , if you under a specific condition such like this</p>

<pre><code>    nginx.ingress.kubernetes.io/configuration-snippet: |
        if ( $host = ^mydomain ) {
          rewrite ^ https://www.mydomain$uri permanent;
        }
</code></pre>

<p>you are unable to make the nginx working again (never config reload success, it will affect the following config change)</p>

<p>Until you delete the ingress rule and re-apply by
<code>kubectl apply -f the-ingress-file</code></p>
