Nginx negative multiple URI rewrite condition
<p>I have setup Nginx to proxy a large number of applications/URLs. The applications are proxied based on their first segment in the path. Each time a application should be proxied a tiny config file with the proxy destination is created for .eg for app1 a app1.conf is created with contents such as this </p>

<pre><code>location /app1/ {
   proxy_pass  http://cloudvm1.vpcxxx:12345;
}
</code></pre>

<p>thirdpartyapp.conf has location proxy as</p>

<pre><code>location /thirdpartyapp/ {
    proxy_pass  http://externalvm.zonexx:23457;
}
</code></pre>

<p>and so on, </p>

<p>The Nginx is configured to listen on both port 80 &amp; 443 (ssl),  As a policy, some applications can be accessed on both ports (ie. http as well as https), where as the rest should be only accessed securely ie https</p>

<p>I tried to code that using the nginx 'if' block such as</p>

<pre><code>server {
    #listen   80; ## listen for ipv4; this line is default and implied
    #listen   [::]:80 default ipv6only=on; ## listen for ipv6

    server_name nginxlb.xxx.com

    # Redirect http to https other than the exceptions below
    if ( $uri !~ ^/(app3|tomcat1|zookeeperxx) ) {
        rewrite ^ https://$server_name$request_uri? permanent;
    }
    ....

   }
</code></pre>

<p>The 'if' condition in the above server block is an attempt to list the set of applications that can be accessed over http, and the rest should be redirected to https</p>

<p>The above 'if' condition doesn't work (it only works for the first 'word' in the regex pattern ie. app3 in the above).</p>

<p>Given that the applications are added extensibly using each application specific location mapping in a separate config file (the nginx reload is invoked for refreshing the mappings). </p>

<p>The desire is to centralize the exception logic (i.e allow http) and not spread/add it in numerous config files.</p>

<p>The nginx version is 1.6.0. Please let me know if I need to provide more details.</p>

<p>Please advise how I can implement the URL match condition for multiple regex patterns.</p>