On my enterprise intranet, websites can be accessed in two ways. With their alias, like https://foo
or with their full address, something like https://foo.example.internal
.
I want to configure my nginx server to force user to use the second option. So if they browse https://foo
, I want the nginx server to rewrite the address to https://foo.example.internal
.
I've tried several options:
http {
server {
server_name foo;
# Test 1
rewrite ^https://foo/(.*)$ https://foo.example.internal/$1;
# Test 2
rewrite ^/foo/(.*)$ https://foo.example.internal/$1;
# Test 3
rewrite ^/(.*) https://foo.example.internal/$1;
}
}
Test1
and Test2
has no effect (i.e. the user may access the website on https://foo
or https://foo.example.internal
), while Test3
does the rewrite from https://foo
to https://foo.example.internal
but the latest does not work (nothing is returned by the nginx server, I suspect that there is some loop in that URL rewrite).
So, how can I force nginx to rewrite https://foo
to https://foo.example.internal
?
Thanks
Finally found the problem. The working solution is done by setting 2 servers: