Welcome! Log In Create A New Profile

Advanced

Two domains and multiple server blocks

Posted by Jamesadamar 
Jamesadamar
Two domains and multiple server blocks
August 12, 2017 09:30AM
Dear community,

I am a beginner in the land of nginx and server administration. From what
I've read so far, setting up nginx to listen to two domains is fairly easy.
All it needs are two distinct server blocks listen to port 80 and with
server_name identical to the domains in question. But it will not work.

I have to domains: www.3jgkp.de and www.armapedia.de. Both a registered by
www.inwx.de and both have A DNS entries to the same server IP 88.99.227.139,
which is my server. For 3.jgkp I use one additional subdomain wiki.3jgkp.de,
which also redirects to this IP.

Now it should suffice to have

server {
listen 80;
listen [::]:80;

server_name .3jgkp.de;

index index.html index.htm index.php;

....
}

server {
listen *:80;
listen [::]:80;

server_name wiki.3jgkp.de;
return 301 https://wiki.3jgkp.de$request_uri;

....

}

server {
listen *:443 ssl;
server_name wiki.3jgkp.de;

index index.php;
root /var/www/wiki/drupal-8.2.6; ## <-- Your only path reference.
client_max_body_size 10m;
ssl_certificate /etc/letsencrypt/live/wiki.3jgkp.de-0001/fullchain.pem;
# managed by Certbot
ssl_certificate_key
/etc/letsencrypt/live/wiki.3jgkp.de-0001/privkey.pem; # managed by Certbot

....
}

for www.3jgkp.de -> that works, both directories are delivered. However,
www.armapedia.de does NOT work:

server {
listen 80;
listen [::]:80;
server_name .armapedia.de;
return 301 https://www.armapedia.de$request_uri;

}

server {
listen 443 ssl;
server_name www.armapedia.de;

root /var/www/armapedia/; ## <-- Your only path reference.
access_log /var/log/nginx/armapedia.de.access.log;
error_log /var/log/nginx/armapedia.de.error.log;

ssl_certificate /etc/letsencrypt/live/www.armapedia.de/fullchain.pem; #
managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/www.armapedia.de/privkey.pem;
# managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
}

Here, whenever I enter www.armapedia.de in my browser, I am redirected to
armapedia.3jgkp.de. I dont understand this behavior at all. All examples
about nginx and multiple vhosts with different domains just use the
appropriate server_name entries, so I'm really stuck here.

Thank you for your help

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,276031,276031#msg-276031

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
basti
Re: Two domains and multiple server blocks
August 12, 2017 10:20AM
Hello,

your server_name .3jgkp.de; and server_name .armapedia.de;
are wrong. Use www.armapedia.de, wildcard, regex or whatever.
See http://nginx.org/en/docs/http/server_names.html

Best Regards,
Basti


On 12.08.2017 09:21, Jamesadamar wrote:
> Dear community,
>
> I am a beginner in the land of nginx and server administration. From what
> I've read so far, setting up nginx to listen to two domains is fairly easy.
> All it needs are two distinct server blocks listen to port 80 and with
> server_name identical to the domains in question. But it will not work.
>
> I have to domains: www.3jgkp.de and www.armapedia.de. Both a registered by
> www.inwx.de and both have A DNS entries to the same server IP 88.99.227.139,
> which is my server. For 3.jgkp I use one additional subdomain wiki.3jgkp.de,
> which also redirects to this IP.
>
> Now it should suffice to have
>
> server {
> listen 80;
> listen [::]:80;
>
> server_name .3jgkp.de;
>
> index index.html index.htm index.php;
>
> ....
> }
>
> server {
> listen *:80;
> listen [::]:80;
>
> server_name wiki.3jgkp.de;
> return 301 https://wiki.3jgkp.de$request_uri;
>
> ....
>
> }
>
> server {
> listen *:443 ssl;
> server_name wiki.3jgkp.de;
>
> index index.php;
> root /var/www/wiki/drupal-8.2.6; ## <-- Your only path reference.
> client_max_body_size 10m;
> ssl_certificate /etc/letsencrypt/live/wiki.3jgkp.de-0001/fullchain.pem;
> # managed by Certbot
> ssl_certificate_key
> /etc/letsencrypt/live/wiki.3jgkp.de-0001/privkey.pem; # managed by Certbot
>
> ....
> }
>
> for www.3jgkp.de -> that works, both directories are delivered. However,
> www.armapedia.de does NOT work:
>
> server {
> listen 80;
> listen [::]:80;
> server_name .armapedia.de;
> return 301 https://www.armapedia.de$request_uri;
>
> }
>
> server {
> listen 443 ssl;
> server_name www.armapedia.de;
>
> root /var/www/armapedia/; ## <-- Your only path reference.
> access_log /var/log/nginx/armapedia.de.access.log;
> error_log /var/log/nginx/armapedia.de.error.log;
>
> ssl_certificate /etc/letsencrypt/live/www.armapedia.de/fullchain.pem; #
> managed by Certbot
> ssl_certificate_key /etc/letsencrypt/live/www.armapedia.de/privkey.pem;
> # managed by Certbot
> include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
> }
>
> Here, whenever I enter www.armapedia.de in my browser, I am redirected to
> armapedia.3jgkp.de. I dont understand this behavior at all. All examples
> about nginx and multiple vhosts with different domains just use the
> appropriate server_name entries, so I'm really stuck here.
>
> Thank you for your help
>
> Posted at Nginx Forum: https://forum.nginx.org/read.php?2,276031,276031#msg-276031
>
> _______________________________________________
> nginx mailing list
> nginx@nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Jamesadamar
Re: Two domains and multiple server blocks
August 12, 2017 11:10AM
They are not wrong, look here:
http://nginx.org/en/docs/http/server_names.html

A special wildcard name in the form “.example.org” can be used to match both
the exact name “example.org” and the wildcard name “*.example.org”.

You should know your own documentation. If it would be wrong, 3.jgkp.de
wouldn't work as it did.

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,276031,276033#msg-276033

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Reinis Rozitis
RE: Two domains and multiple server blocks
August 12, 2017 03:00PM
> Here, whenever I enter www.armapedia.de in my browser, I am redirected to
> armapedia.3jgkp.de. I dont understand this behavior at all. All examples about
> nginx and multiple vhosts with different domains just use the appropriate
> server_name entries, so I'm really stuck here.

First - I would try to upgrade nginx / you are using quite an old (~3 years) version 1.6.2.

I don't particularly remember at what point but there have been some issues/changes on how nginx handles virtual server priority. At least I've seen a similar issue in serving wrong SSL certificates (as in chosing the wrong virtual server block / SNI not working as expected) which went away after upgrade to a most recent version.

While it may not be the case here it's a good point to start for a better support.



Looking at the response headers for armapedia.de:

Connecting to www.armapedia.de (www.armapedia.de)|88.99.227.139|:80... connected.
HTTP request sent, awaiting response...
HTTP/1.1 301 Moved Permanently
Server: nginx/1.6.2
Date: Sat, 12 Aug 2017 12:48:45 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
Set-Cookie: wsc30_cookieHash=3fffeb677df909960a434c5f05d66f2007cde491; path=/; domain=armapedia.3jgkp.de; HttpOnly
Location: http://armapedia.3jgkp.de/


There is a cookie for armapedia.3jgkp.de .. which means that the request is actually passed to php (also the redirect could come from php not nginx) which shouldn’t happen with:
return 301 https://www.armapedia.de$request_uri;

what again indicates that the request is handled by the first server {} block rather than the one you expect.

rr

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Iurii Medvedev
RE: Two domains and multiple server blocks
August 12, 2017 03:10PM
Please don't use server name like .armapedia.de you should USe fqdn

12 авг. 2017 г. 15:58 пользователь "Reinis Rozitis" <[email protected]> написал:

> > Here, whenever I enter www.armapedia.de in my browser, I am redirected
> to
> > armapedia.3jgkp.de. I dont understand this behavior at all. All
> examples about
> > nginx and multiple vhosts with different domains just use the appropriate
> > server_name entries, so I'm really stuck here.
>
> First - I would try to upgrade nginx / you are using quite an old (~3
> years) version 1.6.2.
>
> I don't particularly remember at what point but there have been some
> issues/changes on how nginx handles virtual server priority. At least I've
> seen a similar issue in serving wrong SSL certificates (as in chosing the
> wrong virtual server block / SNI not working as expected) which went away
> after upgrade to a most recent version.
>
> While it may not be the case here it's a good point to start for a better
> support.
>
>
>
> Looking at the response headers for armapedia.de:
>
> Connecting to www.armapedia.de (www.armapedia.de)|88.99.227.139|:80...
> connected.
> HTTP request sent, awaiting response...
> HTTP/1.1 301 Moved Permanently
> Server: nginx/1.6.2
> Date: Sat, 12 Aug 2017 12:48:45 GMT
> Content-Type: text/html; charset=UTF-8
> Connection: keep-alive
> Set-Cookie: wsc30_cookieHash=3fffeb677df909960a434c5f05d66f2007cde491;
> path=/; domain=armapedia.3jgkp.de; HttpOnly
> Location: http://armapedia.3jgkp.de/
>
>
> There is a cookie for armapedia.3jgkp.de .. which means that the request
> is actually passed to php (also the redirect could come from php not nginx)
> which shouldn’t happen with:
> return 301 https://www.armapedia.de$request_uri;
>
> what again indicates that the request is handled by the first server {}
> block rather than the one you expect.
>
> rr
>
> _______________________________________________
> nginx mailing list
> nginx@nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Reinis Rozitis
RE: Two domains and multiple server blocks
August 12, 2017 03:20PM
> Please don't use server name like .armapedia.de you should USe fqdn

Unless you care about micro performance gains (as in a bit slower wildcard lookups) from configuration point of view it's fine and nothing wrong to use .domain.

rr

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Iurii Medvedev
Re: Two domains and multiple server blocks
August 12, 2017 03:20PM
https://nginx.ru/en/docs/http/ngx_http_core_module.html#server_name

2017-08-12 16:11 GMT+03:00 Reinis Rozitis <[email protected]>:

> > Please don't use server name like .armapedia.de you should USe fqdn
>
> Unless you care about micro performance gains (as in a bit slower wildcard
> lookups) from configuration point of view it's fine and nothing wrong to
> use .domain.
>
> rr
>
> _______________________________________________
> nginx mailing list
> nginx@nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx
>



--
With best regards
Iurii Medvedev
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Reinis Rozitis
RE: Two domains and multiple server blocks
August 12, 2017 03:30PM
> From: nginx [mailto:[email protected]x.org] On Behalf Of Iurii Medvedev
>
> https://nginx.ru/en/docs/http/ngx_http_core_module.html#server_name

And?

There is clearly written:

"
The first two of the names mentioned above can be combined in one:
server {
server_name .example.com;
}
"

Which expands to example.com and *.example.com.

The only concern could be performance (similar as with regular expression location blocks).

rr

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Jamesadamar
Re: RE: Two domains and multiple server blocks
August 12, 2017 05:10PM
Thank you Reinis for the tip with the outdated version of Nginx, now I am
using 1.12 ;)

But the problem still remains and it is getting weirder with every minute.

Even if I disable the 3jgkp.conf completely so only one server block
remains, armapedia.de will be redirected to armapedia.3jgkp.de. Maybe that
is because of the cookie you mentioned earlier, but I have no clue how to
delete this information or where this magic redirection is coming from. Can
this be a problem of my DNS configuration? Otherwise, I ran out of any
option left to try or to look into...

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,276031,276039#msg-276039

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Reinis Rozitis
RE: RE: Two domains and multiple server blocks
August 12, 2017 10:10PM
> But the problem still remains and it is getting weirder with every minute.''

I'm not familiar with WoltLab Suite but it feels that it does the same as Wordpress as in it forces redirects to the domain the application is configured.
Could it be that you configured it initially on the 3jgkp.de domain?

For example you can open http://armapedia.de/images/lato/armapedia.png just fine without redirect.

Also if you request http://armapedia.de/somepath it gets redirected to http://armapedia.3jgkp.de/?somepath (which is clearly something based on your provided nginx configuration is not supposed to do)


p.s. one thing to note is that at least the IP you provided (and the domain resolves to) actually doesn't listen on 443 (https) port (unless it's not specifically disabled in firewall it's not public).

rr


_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Jamesadamar
Re: RE: RE: Two domains and multiple server blocks
August 12, 2017 10:20PM
You are absolutely right....I'm feeling like an idiot, really! For weeks
I've tried to change every single character in nginx configuration and your
first tip to look at the request header was worth the number of characters
in gold ;) wsc is indeed the default prefix for Woltlab Suite and indeed,
the first configuration was with the sub domain and not the standalone
domain.

I am sorry to wrongly suspected Nginx to be the source of this problem and
appreciate your help very much, it really killed a lot of sleep time.

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,276031,276041#msg-276041

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Sorry, only registered users may post in this forum.

Click here to login