<html>
<head>
<style>
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
FONT-SIZE: 10pt;
FONT-FAMILY:Tahoma
}
</style>
</head>
<body class='hmmessage'><div style="text-align: left;">Note that the base domain (example.com) redirects fine to WWW (www.example.com).&nbsp; Then adding a 2nd subdomain, API (api.example.com), returns the WWW certificate rather than the API one and flags a trust concern in most browsers.&nbsp; Tried a listen field with both api.example.com:443 and the local interface 127.0.0.1:443, all fail in the same way.&nbsp; Redirect works fine except it returns the incorrect SSL certiicate.<br><br>&nbsp; server {<br>&nbsp;&nbsp;&nbsp; listen api.example.com:443;<br>&nbsp;&nbsp;&nbsp; server_name&nbsp; api.example.com api;<br><br>&nbsp;&nbsp;&nbsp; ssl on;<br>&nbsp;&nbsp;&nbsp; ssl_certificate /opt/local/nginx/certs/api.example.com.crt; <br>&nbsp;&nbsp;&nbsp; ssl_certificate_key /opt/local/nginx/certs/api.example.com.key; <br><br>&nbsp;&nbsp;&nbsp; rewrite ^/(.*) https://www.example.com/$1 permanent;<br>&nbsp; }<br><br>&nbsp; server {<br>&nbsp;&nbsp;&nbsp; listen api.example.com:80;<br>&nbsp;&nbsp;&nbsp; server_name&nbsp; api.example.com api;<br>&nbsp;&nbsp;&nbsp; rewrite ^/(.*) http://www.example.com/$1 permanent;<br>&nbsp; }<br></div><br>Thanks again for looking into this concern,<br>Martian<br><br><hr id="stopSpelling">&gt; Date: Tue, 9 Sep 2008 10:22:15 +0400<br>&gt; From: is@rambler-co.ru<br>&gt; To: nginx@sysoev.ru<br>&gt; Subject: Re: cert handling on redirect of https subdomains<br>&gt; <br>&gt; On Tue, Sep 09, 2008 at 05:51:04AM +0000, Martian Alien wrote:<br>&gt; <br>&gt; &gt; Hi Nginx Group,<br>&gt; &gt; <br>&gt; &gt; Just wanted to start off by saying nginx is a rad web server!  Na zdrowie!<br>&gt; &gt; <br>&gt; &gt; So we've noticed some issues with setting up https ssl certificates over multiple subdomains.<br>&gt; &gt; <br>&gt; &gt; The base domain (example.com) and the first subdomain (www.example.com) work beautifully:<br>&gt; &gt; <br>&gt; &gt;   server {<br>&gt; &gt;     listen www.example.com:443 default;<br>&gt; &gt;     server_name www.example.com;<br>&gt; &gt; <br>&gt; &gt;     ssl on;<br>&gt; &gt;     ssl_certificate /opt/local/nginx/certs/www.example.com.crt; <br>&gt; &gt;     ssl_certificate_key /opt/local/nginx/certs/www.example.com.key; <br>&gt; &gt; <br>&gt; &gt;     location / {<br>&gt; &gt;       # ...<br>&gt; &gt;     }<br>&gt; &gt;   }<br>&gt; &gt; <br>&gt; &gt;   server {<br>&gt; &gt; <br>&gt; &gt;     listen www.example.com:80 default;<br>&gt; &gt; <br>&gt; &gt;     server_name www.example.com;<br>&gt; &gt;     location / {<br>&gt; &gt; <br>&gt; &gt;       # ...<br>&gt; &gt; <br>&gt; &gt;     }<br>&gt; &gt; <br>&gt; &gt;   }<br>&gt; &gt; <br>&gt; &gt; <br>&gt; &gt;   server {<br>&gt; &gt;     listen example.com:443;<br>&gt; &gt;     server_name  example.com;<br>&gt; &gt; <br>&gt; &gt;     ssl on;<br>&gt; &gt;     ssl_certificate /opt/local/nginx/certs/example.com.crt; <br>&gt; &gt;     ssl_certificate_key /opt/local/nginx/certs/example.com.key; <br>&gt; &gt; <br>&gt; &gt;     rewrite ^/(.*) https://www.example.com/$1 permanent;<br>&gt; &gt;   }<br>&gt; &gt; <br>&gt; &gt;   server {<br>&gt; &gt;     server_name  example.com;<br>&gt; &gt;     rewrite ^/(.*) http://www.example.com/$1 permanent;<br>&gt; &gt;   }<br>&gt; &gt; <br>&gt; &gt; NOW, If the following is added, the correct SSL cert for api.example.com is not loaded before the redirect, the www.example.com cert is loaded instead:<br>&gt; &gt; <br>&gt; &gt;   server {<br>&gt; &gt;     listen 127.0.0.1:443;<br>&gt; &gt;     server_name  api.example.com api;<br>&gt; &gt; <br>&gt; &gt;     ssl on;<br>&gt; &gt;     ssl_certificate /opt/local/nginx/certs/api.example.com.crt; <br>&gt; &gt;     ssl_certificate_key /opt/local/nginx/certs/api.example.com.key; <br>&gt; &gt; <br>&gt; &gt;     rewrite ^/(.*) https://www.example.com/$1 permanent;<br>&gt; &gt;   }<br>&gt; &gt; <br>&gt; &gt;   server {<br>&gt; &gt;     listen 127.0.0.1:80;<br>&gt; &gt;     server_name  api.example.com api;<br>&gt; &gt;     rewrite ^/(.*) http://www.example.com/$1 permanent;<br>&gt; &gt;   }<br>&gt; &gt; <br>&gt; &gt; <br>&gt; &gt; Any ideas on how,  to setup multiple SSL / HTTPS subdomains, each with their own cert in nginx?<br>&gt; &gt; <br>&gt; &gt; I've tried many conf variants.  At this point, I'm suspecting it is a bug in nginx, but how would that be possible. =)<br>&gt; <br>&gt; 127.0.0.1 is loopback interface, do you connect to it from outside ?<br>&gt; <br>&gt; <br>&gt; -- <br>&gt; Igor Sysoev<br>&gt; http://sysoev.ru/en/<br>&gt; <br><br /><hr />See how Windows Mobile brings your life together—at home, work, or on the go. <a href='http://clk.atdmt.com/MRT/go/msnnkwxp1020093182mrt/direct/01/' target='_new'>See Now</a></body>
</html>