You have two independent problems:
- Your requests are redirected to
example.com , regardless of which specific domain is originally accessed.
This is because the $server_name variable that you are using is actually a static variable in this server context and is very distant from $http_host .
The correct way would be to use $host (basically this is $http_host with some edge fixing).
- When you try to contact
https://example.com , but not https://www.example.com , you get a connection problem.
There is not enough information in your question to pinpoint the origin of this problem.
This could be a DNS problem ( A / AAAA of example.com records installed on an IP address where the corresponding bindings to the https port are not created).
This could be a problem with an inappropriate certificate:
Does your certificate match both example.com and www.example.com ? If not, then you cannot have both.
If you have separate certificates, you may also need to acquire separate IP addresses or risk to prevent a significant number of users from accessing your site due to lack of SNI .
It should be noted that it should also be noted that usually negligent practice does not have a single notation regarding access to your site. Especially if SEO is bothering you, it is best to decide whether you want to go or not www and stick to it.
cnst
source share