简体   繁体   中英

Redirection issue with two websites running Node.js on Nginx and CloudFlare

I have two files in sites-available , one for each website running on the machine. Both have identical code with only the domain name and port for the website replaced. Both sites are also symlinked to sites-enabled .

reesmorris.co.uk (which works fine):

# Remove WWW from HTTP
server {
    listen 80;
    server_name www.reesmorris.co.uk reesmorris.co.uk;
    return 301 https://reesmorris.co.uk$request_uri;
}

# Remove WWW from HTTPS
server {
    listen 443 ssl;
    ssl_certificate /etc/letsencrypt/live/reesmorris.co.uk/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/reesmorris.co.uk/privkey.pem;
    server_name www.reesmorris.co.uk;
    return 301 https://reesmorris.co.uk$request_uri;
}

# HTTPS request
server {
    # Enable HTTP/2
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name reesmorris.co.uk;

    ssl_certificate /etc/letsencrypt/live/reesmorris.co.uk/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/reesmorris.co.uk/privkey.pem;

    location / {
        proxy_pass http://127.0.0.1:3000;
        include /etc/nginx/proxy_params;
    }
}

francescoiacono.co.uk (has a redirection loop):

# Remove WWW from HTTP
server {
    listen 80;
    server_name www.francescoiacono.co.uk francescoiacono.co.uk;
    return 301 https://francescoiacono.co.uk$request_uri;
}

# Remove WWW from HTTPS
server {
    listen 443 ssl;
    ssl_certificate /etc/letsencrypt/live/francescoiacono.co.uk/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/francescoiacono.co.uk/privkey.pem;
    server_name www.francescoiacono.co.uk;
    return 301 https://francescoiacono.co.uk$request_uri;
}

# HTTPS request
server {
    # Enable HTTP/2
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name francescoiacono.co.uk;

    ssl_certificate /etc/letsencrypt/live/francescoiacono.co.uk/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/francescoiacono.co.uk/privkey.pem;

    location / {
        proxy_pass http://127.0.0.1:4000;
        include /etc/nginx/proxy_params;
    }
}

To experiment, I replaced the return value in the first server block of the broken website to be a 403, which seems to be shown even if the site is using HTTPS. Additionally, removing the first server block on the broken website altogether will cause the website to completely redirect to the already-working website.

Both websites use CloudFlare for the DNS routing. CloudFlare is 'paused' on both websites which means that it only handles the routing, in which both websites have identical routing to the server with AAAA and A records being the same.

I'm not too familiar with server blocks, so if anybody has any ideas as to what is happening then it would be greatly appreciated.

It appears as though this issue was resolved by making both websites 'paused' in the CloudFlare DNS. This was done originally, though may have not had enough time to propagate.

I had not modified the code since this post was created, though I had ensured that both sites were 'paused' on CloudFlare ( reesmorris.co.uk was, however francescoiacono.co.uk was not) - and so it seems to have been a misconfiguration issue with CloudFlare.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM