Report this

What is the reason for this report?

Unexpected redirect on Nginx

Posted on June 23, 2016

Hello,

I have 2 domain and 1 subdomain on 1 droplet (example1.com, example2.com, subdomain.example2.com).

This is my example1.com virtualhost:

#
# Redirect all www to non-www
#
server {
    server_name          www.example1.com;
    ssl_certificate /etc/letsencrypt/live/example1.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example1.com/privkey.pem;

    listen               *:80;
    listen               *:443 ssl spdy;
    listen               [::]:80;
    listen               [::]:443 ssl spdy;

    return 301 https://example1.com$request_uri;
}

#
# Redirect all non-encrypted to encrypted
#
server {
    server_name          example1.com;
    listen               *:80;
    listen               [::]:80;

    return 301 https://example1.com$request_uri;
}

server {
    server_name          example1.com;
    listen               *:443 ssl spdy;
    listen               [::]:443 ssl spdy;

    root /var/www/html/blog;

    ...
}

This is my example2.com virtualhost:

server {
    server_name          example2.com;
    root /var/www/html/example2.com;
    ...
}

This is my subdomain.example2.com virtualhost:

server {
    listen [::]:80;
    server_name subdomain.example2.com;

    root  /var/www/html/subdomain.example2.com;
    ...
}

There are no problem when I browser example1.com and example2.com, but when I go to subdomain.example2.com the browser make a redirect to example1.com

I try clean the browsers cache and nothing.

Greetings.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Start building today

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.