<p>I am trying to create a server-snippet, that will return a 503 for mobile user. I am doing that, by checking the user agent.
The problem:
Server-Snippet is not returning 503 in case of mobile user agent.
All over, the 503 is returned when the user agent is NOT a mobile devide. Mobile itself, sends a 200.
I cannot understand what is done by the Ingress. It seems, as the server-snipper code is somehow parsing it "in a hard-coded way".
Maybe someone got similar issues. If someone might give a hint on such server-snippers, it would be nice.
Thanks </p>

<p>I tried several server-snippets. Please check code below.</p>

<ol>
<li>Try This is a official code snipper from github.</li>
</ol>

<blockquote>
  <p>nginx.ingress.kubernetes.io/server-snippet:    set $agentflag 0;</p>
  
  <p>if ($http_user_agent ~* "(Mobile|ios|android)" ){
      set $agentflag 1;   }</p>
  
  <p>if ( $agentflag = 1 ) {
      return 503;   }</p>
</blockquote>

<p>As json:</p>

<pre><code>"nginx.ingress.kubernetes.io/server-snippet": "| set $agentflag 0; if ($http_user_agent ~* \"(Mobile|ios|android)\" ) { set $agentflag 1; } if ( $agentflag = 1 ) { return 503;}"
</code></pre>

<hr>

<ol start="2">
<li>Try</li>
</ol>

<blockquote>
  <p>nginx.ingress.kubernetes.io/server-snippet: 
        if ($http_user_agent ~* "(Mobile|ios|android)" ){
          return 503;
        }</p>
</blockquote>

<p>As json:</p>

<pre><code>  "nginx.ingress.kubernetes.io/server-snippet": "    if ($http_user_agent ~* (Mobile|ios|android) ) {\n      return 503; }"
</code></pre>

<p>A short working solution is</p>

<pre><code>   annotations: 
      kubernetes.io/ingress.class: private-nginx 
      kubernetes.io/tls-acme: "true" 
      nginx.ingress.kubernetes.io/server-snippet: | 
      if ($http_user_agent ~* "(Mobile)" ) { 
        return 503; 
      }
</code></pre>
