I have a web server with many virtual servers. Only 1 of which is SSL. The problem is, because there is no catchall server block listening for SSL, any https request to the other sites is served by the 1 SSL block.
My configuration, essentially, looks like this:
# the catch all
server {
listen 80 default;
# I could add this, but since I have no default cert, I cannot enable SSL,
# and this listen ends up doing nothing (apparently).
# listen 443;
server_name _;
# ...
}
# some server
server {
listen 80;
server_name server1.com;
# ...
}
# some other server ...
server {
listen 80;
server_name server2.com;
# ...
}
# ... and it's https equivalent
server {
listen 443;
ssl on;
server_name server2.com;
# ...
}
Now as there's no default listener for 443, a request like https://server1.com
will end up being served by the server2.com
https block. This follows the logic for server_name
in the docs.
If there is no match, a server { ... } block in the configuration file will be used based on the following order:
- the server block with a matching listen directive marked as [default|default_server]
- the first server block with a matching listen directive (or implicit listen 80;)
What is the preferred solution for this problem? Do I need to set up dummy cert for my catch all server block just so I can listen on 443 and handle the bad requests? Is there a parameter I'm unaware of that forces an exact hostname match with server
?