How Can I reverse this redirect?

October 7, 2019 549 views
Nginx Configuration Management WordPress

I have no idea how this happened but after moving my site (xxxx.nz) into a new droplet from my old vps, while I was generating a Let’s Encrypt certificate a 301 re-direct has appeared to a completely non related domain (yyyy.nz) on my server…

My question is - How can I best reverse This?

This is the HTTP Status:

:~$ curl -I https://xxxx.nz
HTTP/2 301 
server: nginx
date: Sun, 06 Oct 2019 23:57:55 GMT
content-type: text/html; charset=UTF-8
location: https://yyyy.nz/
expires: Wed, 11 Jan 1984 05:00:00 GMT
cache-control: no-transform, no-cache, must-revalidate, max-age=0
x-redirect-by: WordPress
strict-transport-security: max-age=31536000; includeSubdomains
content-security-policy: default-src 'self' https: data: 'unsafe-inline' 'unsafe-eval';
x-xss-protection: 1; mode=block
x-frame-options: SAMEORIGIN
x-content-type-options: nosniff 

this is the sites-enabled Host File:

:~$ cat /etc/nginx/sites-enabled/xxxx.nz

server {

    server_name xxxx.nz www.xxxx.nz;

    access_log /home/xxxx.nz/logs/access.log;
    error_log /home/xxxx.nz/logs/error.log;

    root /home/xxxx.nz/public/;
    index index.php;

    location / {
        try_files $uri $uri/ /index.php?$args; 
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/run/php/php7.2-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }

    listen [::]:443 ssl http2; # managed by Certbot
    listen 443 ssl http2; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/xxxx.nz/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/xxxx.nz/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}
server {
    if ($host = www.xxxx.nz) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    listen 80;
    listen [::]:80;

    server_name xxxx.nz www.xxxx.nz;
    return 404; # managed by Certbot


}

This is the Nginx.conf file:

:~$ cat /etc/nginx/nginx.conf

user matt;
worker_processes 4;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
    worker_connections 4096;
    multi_accept on;
}

http {

    ##
    # Basic Settings
    ##

    ssl_session_cache shared:SSL:10m;
    ssl_session_timeout 10m;    
    add_header Strict-Transport-Security "max-age=31536000; includeSubdomains";
    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 15;
    types_hash_max_size 2048;
    server_tokens off;
    client_max_body_size 64m;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ##
    # SSL Settings
    ##

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;

    # gzip_vary on;
    gzip_proxied any;
    gzip_comp_level 2;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

    ##
    # Cache Settings
    ##

    fastcgi_cache_key "$scheme$request_method$host$request_uri";
    add_header Fastcgi-Cache $upstream_cache_status;


    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name _;
    return 444;
}

server {
    listen 80;
    listen [::]:80;
    server_name xxxx.com;

    return 301 https://$server_name$request_uri;
}



    ##
    # Security
    ##

    add_header Content-Security-Policy "default-src 'self' https: data: 'unsafe-inline' 'unsafe-eval';" always;
    add_header X-Xss-Protection "1; mode=block" always;
    add_header X-Frame-Options "SAMEORIGIN" always;
    add_header X-Content-Type-Options "nosniff" always;

}

Many thanks in advance for any guidance you can offer

Matt

1 Answer

Hi @thinknew,

It’s a bit hard looking at the configuration like that with yyyy and zzzz however from what I could see, everything looks alright. This leads me to believe the redirection is coming from your website/application rather than the Nginx configuration.

Is it by any chance possible you copied the website from yyyy.nz to xxxx.nz? Check your database if you have hardcoded the yyyy.nz website.

Another thing to check is your files and if you have hardcoded yyyy.nz in there as well.

Kind regards,
Kalin

  • Hi @Kalin

    Thanks for tacking the time to get back to me. I apologise for the xxxx.nz - its just the system would not post my question when I left the full URLs in - It just hung for ages - I thought maybe no links were allowed but it must have just been a coincidence that when I removed the URL the question went through.

    Anyhow - The Domains we are working with are:
    tacklepro.nz
    promarine.nz

    here’s where it gets weird…

    When I sent in the config files yesterday it was tacklepro that was re-directing to promarine.... when I checked this morning - promarine is now re-directing to tacklepro

    https://www.ssllabs.com/ssltest/analyze.html?d=promarine.nz

    {matt@saturn:~$ curl -I https://promarine.nz
    HTTP/2 301
    server: nginx
    date: Tue, 08 Oct 2019 00:41:34 GMT
    content-type: text/html; charset=UTF-8
    location: https://tacklepro.nz/
    expires: Wed, 11 Jan 1984 05:00:00 GMT
    cache-control: no-transform, no-cache, must-revalidate, max-age=0
    x-redirect-by: WordPress
    strict-transport-security: max-age=31536000; includeSubdomains
    fastcgi-cache: MISS
    content-security-policy: default-src ‘self’ https: data: 'unsafe-inline’ 'unsafe-eval’;
    x-xss-protection: 1; mode=block
    x-frame-options: SAMEORIGIN
    x-content-type-options: nosniff}

    I did not copy these sites however I did copy the config file and switch over the URLs

    I’ve checked the htaccess file for a re-direct :
    {matt@saturn:~$ cat ~/promarine.nz/public/.htaccess

    BEGIN WordPress

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index.php$ - [L]
    RewriteCond %{REQUESTFILENAME} !-f
    RewriteCond %{REQUEST
    FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>}

    and the database reflects the correct site_url…

    Any other Ideas where I can check?

    Many thanks in advance

    Matt

Have another answer? Share your knowledge.