0

I have setup a multilangual Wordpress multiste site on an nginx server (the current english page is not translated yet but it is coming):

  • English version: appscaptain.com
  • Danish version: appscaptain.dk

Both should redirect from the www to non-www respectively.

www.appscaptain.com currently redirects correctly to appscaptain.com, but for some reason:

  • appscaptain.dk sometimes redirects to appscaptain.com and
  • www.appscaptain.dk sometimes doesn't redirect to appscaptain.dk, but instead to appscaptain.com.

It's weird that it doesn't happen consistently.

Can anyone spot the issue in the Nginx rule?

server {
    listen 80;
    server_name appscaptain.com www.appscaptain.com appscaptain.dk www.appscaptain.dk;
    rewrite ^ (.*) https: //appscaptain.com$1 permanent;
}
server {
    listen 443 ssl http2;
    server_name www.appscaptain.com;
    return 301 https: //appscaptain.com$request_uri;
    ssl_certificate / etc / nginx / auth - acme / appscaptain.com / appscaptain.com.crt;
    ssl_certificate_key / etc / nginx / auth - acme / appscaptain.com / appscaptain.com.key;
    ssl_session_cache shared: SSL: 10m;
    ssl_session_timeout 10m;
    ssl_prefer_server_ciphers on;
    include / etc / nginx / conf / ssl - protocol - cipher.conf;
    ssl_stapling on;
    ssl_stapling_verify on;
    resolver 8.8.8.8 8.8.4.4 valid = 300s;
    resolver_timeout 30s;
    ssl_trusted_certificate / etc / nginx / auth - acme / appscaptain.com / appscaptain.com.ca;
    ssl_buffer_size 1400;
    ssl_session_tickets on;
    add_header Strict - Transport - Security max - age = 31536000;
    access_log off;
    access_log / home / appscaptain.com / logs / access_log;
    error_log off;
    error_log / home / appscaptain.com / logs / error.log;
    add_header X - Frame - Options SAMEORIGIN;
    add_header X - Content - Type - Options nosniff;
    add_header X - XSS - Protection "1; mode=block";
}
server {
    listen 443 ssl http2;
    ssl_certificate / etc / nginx / auth - acme / appscaptain.com / appscaptain.com.crt;
    ssl_certificate_key / etc / nginx / auth - acme / appscaptain.com / appscaptain.com.key;
    ssl_session_cache shared: SSL: 10m;
    ssl_session_timeout 10m;
    ssl_prefer_server_ciphers on;
    include / etc / nginx / conf / ssl - protocol - cipher.conf;
    ssl_stapling on;
    ssl_stapling_verify on;
    resolver 8.8.8.8 8.8.4.4 valid = 300s;
    resolver_timeout 30s;
    ssl_trusted_certificate / etc / nginx / auth - acme / appscaptain.com / appscaptain.com.ca;
    ssl_buffer_size 1400;
    ssl_session_tickets on;
    add_header Strict - Transport - Security max - age = 31536000;
    access_log off;
    access_log / home / appscaptain.com / logs / access_log;
    error_log off;
    error_log / home / appscaptain.com / logs / error.log;
    add_header X - Frame - Options SAMEORIGIN;
    add_header X - Content - Type - Options nosniff;
    add_header X - XSS - Protection "1; mode=block";
    root / home / appscaptain.com / public_html;
    include / etc / nginx / conf / ddos2.conf;
    index index.php index.html index.htm;
    server_name appscaptain.com appscaptain.dk www.appscaptain.dk;

P.S. It is setup under 1 nginx rule and one wordpress directory to make the localization domain mapping work (Polylang). I can't split it under two separate rule files.

Anders N
  • 3
  • 3
  • There seems to be inconsistencies in your `server_name` statements. The first block redirects `dk` to `com` and the third block handles `www.dk` without redirection. – Richard Smith Apr 15 '18 at 14:25
  • Thanks @RichardSmith. The reason why I set it like that was to implement this: "All domains must point to the same directory (where the WordPress index.php is present).". That's what I thought I had done here. Any idea how I can do that correctly (while keeping the www to non-www redirects)? – Anders N Apr 15 '18 at 15:53
  • Please do not paste configuration files into Google Translate. Just insert them directly into your post. – Michael Hampton Apr 15 '18 at 17:58
  • Hi @MichaelHampton No worries, I have not pasted anything into Google translate. I meant that I would translate the webpage itself - not the configuration file. – Anders N Apr 15 '18 at 19:41
  • OK, well, what happened to the nginx configuration you pasted? It appears to have been mangled by _something_. – Michael Hampton Apr 15 '18 at 19:41
  • @MichaelHampton Sorry, I'm a noob here. Had some issues making the code show up as code. Maybe it was the Chrome beautify extension that was supposed to do it that has caused it. What is the correct way to insert code here. Do I have to manually indent every line with 4 spaces? – Anders N Apr 17 '18 at 06:43

1 Answers1

0

Try this, I make this un effecient just for make everything clear,also you need to use another config on wordpress so then it can accept both domain. Looks like there is something wrong with your config copy-paste,

   server {
    listen 80;
    server_name appscaptain.com www.appscaptain.com ;
    rewrite ^ (.*) https://appscaptain.com$1 permanent;
}

server {
    listen 80;
    server_name appscaptain.dk www.appscaptain.dk;
    rewrite ^ (.*) https://appscaptain.dk$1 permanent;
}

server {
    listen 443 ssl http2;
    server_name www.appscaptain.com;
    return 301 https://appscaptain.com$request_uri;
    ..... >> SSL config to your ssl cert
}

server {
    listen 443 ssl http2;
    server_name www.appscaptain.dk;
    return 301 https://appscaptain.dk$request_uri;
    ..... >> SSL config to your ssl cert
}

server {
    listen 443 ssl http2;
    server_name appscaptain.com appscaptain.dk;
    .................. >>> Your config here including your index root

}
rosada
  • 16
  • 3