Question

Nginx redirects to the wrong domain

I have 3 domains setup, 1 is irrelevant, and 1 is new. The problem is that it redirects, I think, to my other domain. I say I think because Firefox/Chrome give an error due to mismatch to name provided in the certificate: it uses the name of my other domain. Safari on the other hand displays the default Nginx page.

Check this:

https://check-your-website.server-daten.de/?q=gleep.app

It shows that the certificate and even screenshots come from my other domain, looxapp.gr

I have read a million other topics like this but I still can’t solve it.

gleep.app:

server {

        root /gleep/admin/build;
        index index.html index.htm index.nginx-debian.html;

        server_name www.gleep.app gleep.app;

        location / {
        try_files $uri $uri/ /index.html;
#               try_files $uri $uri/ =404;
#         proxy_pass http://localhost:8085;
         proxy_http_version 1.1;
         proxy_set_header Upgrade $http_upgrade;
         proxy_set_header Connection 'upgrade';
         proxy_set_header Host $host;
         proxy_cache_bypass $http_upgrade;
       }
    listen [::]:80;


    listen [::]:443 ssl ipv6only=on;  # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/gleep.app/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/gleep.app/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


}


looxapp.gr: (bar and admin subdomains don’t work but that’s ok)

server {

        root /looxbrowser/build;
        index index.html index.htm index.nginx-debian.html;

        server_name looxapp.gr www.looxapp.gr;

        location / {
	try_files $uri $uri/ /index.html;
                #try_files $uri $uri/ =404;
#         proxy_pass http://localhost:8083;
         proxy_http_version 1.1;
         proxy_set_header Upgrade $http_upgrade;
         proxy_set_header Connection 'upgrade';
         proxy_set_header Host $host;
         proxy_cache_bypass $http_upgrade;
        }

    listen [::]:443 ssl; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/looxapp.gr/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/looxapp.gr/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 {

	root /looxbar/build;
	index index.html index.html index.nginx-debian.html;

	server_name bar.looxapp.gr;

	location / {
		try_files $uri $uri/ =404;
		proxy_pass http://localhost:8083;
		proxy_http_version 1.1;
	proxy_set_header Upgrade $http_upgrade;
	proxy_set_header Connection 'upgrade';
	proxy_set_header Host $host;
	proxy_cache_bypass $http_upgrade;

	}

    listen [::]:443 ssl; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/looxapp.gr/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/looxapp.gr/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 {
	root /admin/build/;
	index index.html index.html index.nginx-debian.html;
	
	server_name admin.looxapp.gr;
	location / {
		try_files $uri $uri/ /index.html;
		proxy_http_version 1.1;
		proxy_set_header Upgrade $http_upgrade;
		proxy_set_header Connection 'upgrade';
		proxy_set_header Host $host;
		proxy_cache_bypass $http_upgrade;

	}


    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/looxapp.gr/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/looxapp.gr/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.looxapp.gr) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    if ($host = looxapp.gr) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


	listen 80;	
        listen [::]:80;

        server_name looxapp.gr www.looxapp.gr;
    return 404; # managed by Certbot




}

server {
    if ($host = bar.looxapp.gr) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


	listen 80;
	listen [::]:80;

	server_name bar.looxapp.gr;
    return 404; # managed by Certbot


}

server {
    if ($host = admin.looxapp.gr) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


	
	server_name admin.looxapp.gr;
    listen 80;
    return 404; # managed by Certbot


}

Show comments

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi there @tkmkds,

I think that this is because you have proxy rules but you have not specified the proxy_pass for your domains. Do you need the reverse proxy rules or do you want your websites to be only loading the content of the document root that you’ve specified?

What I could suggest is using the Nginx tool to generate your Nginx configuration:

https://www.digitalocean.com/community/tools/nginx

It allows you to add multiple sites, SSL server blocks and also create reverse proxy setup.

Regards, Bobby