title: Nginx redirects to unwanted port
body: <p>I’m trying to host 2 different websites - one static non-wordpress site, and one wordpress subdomain site - on my own pi server (test sites). Whenever accessing the subdomain site test.mysite.co.uk, it instead loads test.mysite.co.uk:4323 at the unwanted port 4323. The main mysite.co.uk site loads correctly however.</p>
  <p>Initially I’ve been running these test sites locally (on different ports - the main site on port 4321 and subdomain on 4323) until I decided to deploy them using real domain names. However, presumably you cannot configure DNS to point to a specific IP and port (presumably a DNS record just points to an IP only), so I changed both the 2 domains’ conf files to listen to port 80 (as apparently you can define the server names to tell nginx which site to load - called virtual hosts?). Note that I have DNS A records for mysite.co.uk and test.mysite.co.uk that both point to the same public IP address of my router.</p>
  <p>Nowhere is there a reference to port 4323 anymore, so I am confused as to why the subdomain still insists on forwarding to that port. I’ve been using incognito mode on chrome so there should be no caching issues. My router forwards external port 80 to internal port 80, and I’ve restarted the nginx server multiple times. The default port of my pi itself is no longer 80.</p>
  <p>Here’s the /etc/nginx/sites-available/mysite.co.uk.conf file:</p>
  <pre><code>server {
      listen 80;
      listen [::]:80;
  
      root /var/www/mysite.co.uk;
  
      # Add index.php to the list if you are using PHP
      index index.html index.htm index.nginx-debian.html;
  
      server_name mysite.co.uk www.mysite.co.uk;
  
      location / {
          # First attempt to serve request as file, then
          # as directory, then fall back to displaying a 404.
          try_files $uri $uri/ =404;
      }
  }
  </code></pre>
  <p>And here’s the /etc/nginx/sites-available/test.mysite.co.uk.conf file:</p>
  <pre><code>upstream wp-php-handler {
          server unix:/var/run/php/php7.4-fpm.sock;
  }
  server {
          listen 80;
          server_name test.mysite.co.uk;
          root /var/www/wp.mysite.co.uk;
          index index.php;
          location / {
                  try_files $uri $uri/ /index.php?$args;
          }
          location ~ \.php$ {
                  include snippets/fastcgi-php.conf;
                  fastcgi_pass wp-php-handler;
          }
  }
  </code></pre>
  <p>Both .conf files are also symlinked to their respective sites-enabled folders.</p>
  <p>Not sure if this means anything but loading local_ip:80 (or without :80 as presumably it assumes :80) in a web browser returns the Apache2 Ubuntu Default Page.</p>
  <p>As per <a href="https://serverfault.com/questions/351212/nginx-redirects-to-port-8080-when-accessing-url-without-slash">this post</a>, I’ve tried adding <code>port_in_redirect off</code>, <code>autoindex on</code> and <code>proxy_redirect http://test.mysite.co.uk:4323/ http://test.mysite.co.uk/</code> but to no avail.</p>
  <p>Does anyone have any ideas of what I’m doing wrong?</p>
  <p><strong>UPDATE:</strong></p>
  <p>I've managed to create another test non-wordpress site that's exactly the same as the first non-wordpress site but called copy.mysite.co.uk, which seems to work. I'm assuming the problem with the wordpress test site may be to do with its config (although I can't see anything wrong with the code I've listed here)?</p>