Nginx proxy pass subdomain, node vhost
<p>I have some trouble with nginx proxy_pass redirection on localhost subdomain. I have a domain &quot;domain.com&quot;, i want to redirect all request on *.domain.com on *.localhost:9000. Then node handle all request on *.localhost:9000 to the good express app.</p>
<p>On nginx conf when i try the following :</p>
<pre><code>server {
    server_name extranet.domain.com;
    listen 80;
    location / {
       proxy_pass http://extranet.localhost:9000;
    }
}
</code></pre>
<p>Request on <code>extranet.domain.com</code> are well redirected to the good express webapp.</p>
<p>With this :</p>
<pre><code>server {
    server_name ~^(.*?)\.domain\.com$;
    listen 80;
    location / {
       proxy_pass http://localhost:9000/$1;
    }
}
</code></pre>
<p>Express app running on <code>localhost:9000</code> handle request /mysubdomainname, which implie that regex is good.</p>
<p>But when i try :</p>
<pre><code>server {
    server_name ~^(.*?)\.domain\.com$;
    listen 80;
    location / {
       proxy_pass http://$1.localhost:9000;
    }
}
</code></pre>
<p>All request on *.domain.com return http code 502.
Why <code>http://localhost:9000/$1;</code> works and not <code>http://$1.localhost:9000;</code> ?
(all subdomain are set in <code>/etc/hosts</code>).</p>
<p>Thanks in advance. I'm totally lost !</p>