title: Only listen to ONE Subdomain and ONE Port
body: <p>I need to find out how to listen to only one port-hostname combination and to return 404 on every other request.</p>
  
  <p>My example:</p>
  
  <p>I have set up a subdomain for owncloud that uses SSL and listens to port 12345 instead of 443. Let's assume this subdomain is oc.example.com. So I want nginx to <strong>only listen to</strong> <a href="https://oc.example.com:12345" rel="nofollow">https://oc.example.com:12345</a> but not to</p>
  
  <ul>
  <li><strong>http</strong>://oc.example.com:12345</li>
  <li><a href="https://oc.example.com" rel="nofollow">https://oc.example.com</a>:<strong>X</strong> where X != 12345</li>
  <li>https://<strong>BLABLA</strong>.example.com:12345</li>
  <li><strong><a href="http://IP.IP.IP.IP" rel="nofollow">http://IP.IP.IP.IP</a></strong>:12345</li>
  <li><strong>https</strong>://IP.IP.IP.IP:12345 </li>
  <li>and so on</li>
  </ul>
  
  <p>If one requests any resource that does not exactly match <a href="https://oc.example.com:12345" rel="nofollow">https://oc.example.com:12345</a> an error (e.g. 404 not found) should be returned or the server simply should not respond. </p>
  
  <p>My config so far looks like:</p>
  
  <pre><code>server {
      # I think there's something wrong here?
      listen 12345;
      server_name oc.example.com;
      ssl on;
  
      ssl_certificate /etc/ssl/nginx/owncloud/owncloud.crt;
      ssl_certificate_key /etc/ssl/nginx/owncloud/owncloud.key;
  
      add_header Strict-Transport-Security max-age=31536000;
      add_header X-Frame-Options DENY;
  
       # Path to the root of your installation
      root /var/some/path/to/my/owncloud/;
  
      client_max_body_size 10G; # set max upload size
      fastcgi_buffers 64 4K;
  
      rewrite ^/caldav(.*)$ /remote.php/caldav$1 redirect;
      rewrite ^/carddav(.*)$ /remote.php/carddav$1 redirect;
      rewrite ^/webdav(.*)$ /remote.php/webdav$1 redirect;
  
      index index.php;
      error_page 403 = /core/templates/403.php;
      error_page 404 = /core/templates/404.php;
  
      ... here are the definitions of my locations
  }
  </code></pre>
  
  <p>I read the documentation and found that nginx first looks for the correct server definition by the port number. If there are multiple matches the server_name is used to find the correct definition. But I only have one definition!</p>
  
  <p>Does somebody know how to solve the problem?</p>