0

I have a server on which I run a website at the domain example.eu. I've redirected to https and removed the www as per this answer. I now wish to add another website to the same server, at the domain test.eu. This server doesn't need www removal or https, so it is a simple server block.

The problem is that whenever I go to test.eu in my browser, I get a 301 redirect to example.eu.

example.eu conf:

upstream django {
    server unix:///home/foo/bar/example.sock; # for a file socket
}

server {
    listen 80;
    server_name example.eu www.example.eu;
    return 301 https://example.eu$request_uri;
}

server {
    listen 443 ssl;
    server_name www.example.eu;
    ssl_certificate /etc/nginx/ssl/example.cer;
    ssl_certificate_key /etc/nginx/ssl/example.key;
    return 301 https://example.eu$request_uri;
}

server {
    listen 443 ssl;
    server_name example.eu;
    ssl_certificate /etc/nginx/ssl/example.cer;
    ssl_certificate_key /etc/nginx/ssl/example.key;
    root /usr/share/nginx/html;
    index index.php;

    location /static { # STATIC_URL
        alias /home/foo/bar/static; # STATIC_ROOT
        expires max;
        add_header Pragma public;
        add_header Cache-Control "public";
    }

    location /media { # MEDIA_URL
        root /home/foo/bar/media; # MEDIA_ROOT
    }

    location / {
        include /etc/nginx/uwsgi_params;
        uwsgi_read_timeout 300;
        uwsgi_pass django;
    }
}

and the much simpler test.eu conf:

server {
    listen 80;
    server_name test.eu www.test.eu;
    root /home/foo/qux;
    index index.html;
}

I've also tried having the test.eu conf as part of the example.eu conf, at the top, but to no avail. What's going on and how do I fix this? Many thanks.

3

It turns out that I was changing the conf files around and forgot to clear my cache, so the browser was caching the redirect. Fixed now.

  • I would, but I have to wait 2 days from when I posted the answer. – heidi Jun 29 '16 at 12:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.