0

I am using following Nginx configuration block

server {
    listen 80;
    server_name MyDomain.co.uk www.MyDomain.co.uk *.MyDomain.co.uk;
    return 301 https://www.MyDomain.co.uk$request_uri;
       }

server {
    listen 443;
    server_name MyDomain.co.uk www.MyDomain.co.uk *.MyDomain.co.uk;
    access_log /var/www/vhosts/MyDomain.co.uk/logs/access.log;
    error_log /var/www/vhosts/MyDomain.co.uk/logs/error.log;
    root /var/www/vhosts/MyDomain.co.uk/httpdocs;

    ssl on;
    ssl_certificate      /etc/nginx/ssl/MyDomain.co.uk.crt;
    ssl_certificate_key  /etc/nginx/ssl/MyDomain.co.uk.key;
    ssl_protocols        TLSv1.1 TLSv1.2;
...
...
...
}

this is to achieve that all traffic which comes to my website via following

  • http://MyDomain.co.uk
  • http://www.MyDomain.co.uk
  • https://MyDomain.co.uk

should always be forwarded to https://www.MyDomain.co.uk but I am having 2 issues

  1. Everything is fine but https://MyDomain.co.uk never forwards to https://www.MyDomain.co.uk not sure why but could it be due to fact that my certificate is only valid for www.MyDomain.co.uk and not for domain MyDomain.co.uk? but I have seen other posts in this forums where users are achieving this if I am not wrong?

  2. After making above change of Nginx block configuration to forward non-https to https and non-www to www for some reason my Magento back-end is not working, I can login to backend fine but when I try to do anything like flushing the cache or any other function it always says following and nothing is done magento_backend_issue

Could it be because most of the settings of Nginx is under SSL block?

AD7six
  • 2,920
  • 2
  • 21
  • 23
Farmi
  • 379
  • 1
  • 4
  • 17

1 Answers1

0

Edited answer to include full configuration.

Your https://MyDomain.co.uk doesn't forward to https://www.MyDomain.co.uk because you have the MyDomain.co.uk domain in your https block, which doesn't have any redirects.

You should remove MyDomain.co.uk and *.MyDomain.co.uk from your current server block that listens on 443 port, and you should add the following block:

server {
    listen 80;
    server_name MyDomain.co.uk www.MyDomain.co.uk *.MyDomain.co.uk;
    return 301 https://www.MyDomain.co.uk$request_uri;
}

server {
    listen 443;

    server_name MyDomain.co.uk *.MyDomain.co.uk;
    ssl on;
    ssl_certificate      /etc/nginx/ssl/MyDomain.co.uk.crt;
    ssl_certificate_key  /etc/nginx/ssl/MyDomain.co.uk.key;
    ssl_protocols        TLSv1.1 TLSv1.2;

    return 301 https://www.MyDomain.co.uk$request_uri;
}

server {
    listen 443;
    server_name www.MyDomain.co.uk;
    access_log /var/www/vhosts/MyDomain.co.uk/logs/access.log;
    error_log /var/www/vhosts/MyDomain.co.uk/logs/error.log;
    root /var/www/vhosts/MyDomain.co.uk/httpdocs;

    ssl on;
    ssl_certificate      /etc/nginx/ssl/MyDomain.co.uk.crt;
    ssl_certificate_key  /etc/nginx/ssl/MyDomain.co.uk.key;
    ssl_protocols        TLSv1.1 TLSv1.2;
}

This way you will have a server block for redirecting the other domains, and then the main server block which will process the request.

So, you have three vhosts:

1) http, which redirects all requests to www.MyDomain.co.uk 2) https, which redirects MyDomain.co.uk and *.MyDomain.co.uk requests to www.MyDomain.co.uk 3) https for processing the final request to www.MyDomain.co.uk.

Tero Kilkanen
  • 36,796
  • 3
  • 41
  • 63
  • Can you please elaborate? do you mean to change port 80 server block? – Farmi Sep 19 '15 at 12:28
  • Sorry for the late comment, I've had some health problems and now I'm full back in action. You don't need to change the port 80 server block, it handles the redirects correctly already. However, you need to add a separate port 443 server block for the other domains you want to redirect to www.MyDomain.co.uk, and add the redirect there. – Tero Kilkanen Jan 19 '16 at 10:58