title: Wordpress multisite Nginx redirect loop
body: <p>I'm pretty sure this is just a basic config thing. I've got a wordpress multisite up and running, with base domains. I want to implement simple domain mapping, unfortunately the Wordpress documentation for nginx config is pretty lacking.</p>
  <p>I tried and succeeded doing this using the <a href="https://odd.blog/wordpress-mu-domain-mapping/" rel="nofollow noreferrer">WU Domain Mapping plugin</a> 9 months ago, but it isn't working this time round, and I'd rather have it working without the plugin (aiming for a low plugin WP installation).</p>
  <p>Of course, I've amended the site URL in the sites section to test this.</p>
  <p>What I currently have is:</p>
  <pre><code>site1.com (working)
  site2.site1.com (working)
  site2.com (301 redirect loop)
  </code></pre>
  <p>What I want is:</p>
  <pre><code>site1.com
  site2.com
  </code></pre>
  <p>Any suggestions what I need to add to my Nginx conf file? My current nginx conf file is pretty much the same as that of the <a href="https://www.digitalocean.com/community/tutorials/how-to-install-wordpress-with-docker-compose" rel="nofollow noreferrer">Digital Ocean Docker</a> set up page:</p>
  <pre><code>server {
          listen 80;
          listen [::]:80;
  
  
          server_name *.site1.com site1.com www.site1.com;
  
          location ~ /.well-known/acme-challenge {
                  allow all;
                  root /var/www/html;
          }
  
          location / {
                  rewrite ^ https://$host$request_uri? permanent;
          }
  
  
          error_log    /var/log/nginx/error.log;
          access_log  /var/log/nginx/access.log;
          }
  
  server {
  
          error_log    /var/log/nginx/error.log;
          access_log  /var/log/nginx/access.log;
  
          listen 443 ssl http2;
          listen [::]:443 ssl http2;
          server_name site1.com www.site1.com;
  
          index index.php index.html index.htm;
  
          root /var/www/html;
  
          server_tokens off;
  
          ssl_certificate /etc/letsencrypt/live/site1.com/fullchain.pem;
          ssl_certificate_key /etc/letsencrypt/live/site1.com/privkey.pem;
  
          include /etc/nginx/conf.d/options-ssl-nginx.conf;
  
          add_header X-Frame-Options &quot;SAMEORIGIN&quot; always;
          add_header X-XSS-Protection &quot;1; mode=block&quot; always;
          add_header X-Content-Type-Options &quot;nosniff&quot; always;
          add_header Referrer-Policy &quot;no-referrer-when-downgrade&quot; always;
          add_header Content-Security-Policy &quot;default-src * data: 'unsafe-eval' 'unsafe-inline'&quot; always;
          # add_header Strict-Transport-Security &quot;max-age=31536000; includeSubDomains; preload&quot; always;
          # enable strict transport security only if you understand the implications
  
          location / {
                  try_files $uri $uri/ /index.php$is_args$args;
          }
  
          location ~ \.php$ {
                  try_files $uri =404;
                  fastcgi_split_path_info ^(.+\.php)(/.+)$;
                  fastcgi_pass wordpress:9000;
                  fastcgi_index index.php;
                  include fastcgi_params;
                  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                  fastcgi_param PATH_INFO $fastcgi_path_info;
          }
  
          location ~ /\.ht {
                  deny all;
          }
  
          location = /favicon.ico {
                  log_not_found off; access_log off;
          }
          location = /robots.txt {
                  log_not_found off; access_log off; allow all;
          }
          location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
                  expires max;
                  log_not_found off;
          }
  }
  </code></pre>
  <p>UPDATE:</p>
  <p>Checking in the nginx Docker if I log in and run the <code>nginx</code> command, I get these error messages :
  <em>EDIT - this is also happening on the working configuration so I'm guessing it may be a red herring</em></p>
  <pre><code>nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
  2021/03/18 10:07:11 [emerg] 29#29: bind() to [::]:80 failed (98: Address already in use)
  nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
  2021/03/18 10:07:11 [emerg] 29#29: bind() to 0.0.0.0:443 failed (98: Address already in use)
  nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)
  2021/03/18 10:07:11 [emerg] 29#29: bind() to [::]:443 failed (98: Address already in use)
  nginx: [emerg] bind() to [::]:443 failed (98: Address already in use)
  2021/03/18 10:07:11 [emerg] 29#29: still could not bind()
  </code></pre>
  <p>Inside the container, <em>netstat</em> gives me this for ports 80/443:</p>
  <pre><code>tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      1/nginx: master pro
  tcp        0      0 172.18.0.2:38422        199.232.138.132:80      TIME_WAIT   -
  tcp6       0      0 :::80                   :::*                    LISTEN      1/nginx: master pro
  tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      1/nginx: master pro
  tcp6       0      0 :::443                  :::*                    LISTEN      1/nginx: master pro
  </code></pre>
  <p>Outside the container it seems to be correctly running just 1 port:</p>
  <pre><code>tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      1298/docker-proxy
  tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      1313/docker-proxy
  </code></pre>
  <p>EDIT (18/3/21):</p>
  <p>Just did a restore from a working back up at another IP address and I'm still having issues with this particular domain. Funnily enough, I span up another site with a different domain and that one is working!</p>
  <p>I'll check the config to see if there's anything in there that's different, if not, I think I need to go down the DNS route, checking whether that's correctly aimed at my host or not.</p>