I have a server with 2 websites. Let's call them foo.com
and bar.com
.
foo.com
has a subdomain, called mail.foo.com
.
Both foo.com
and bar.com
are WordPress sites, and their NGINX configuration is the usual WP configuration you'd find in WP's instructions.
I also have a docker that is running a Mailcow
image, which is listening on ports 0.0.0.0:3333 (http)
and 0.0.0.0:3334 (https)
.
Is there a way I can configure NGINX so that opening a browser and going to:
foo.com
will show my sitefoo
bar.com
will show my sitebar
(those two points are currently working as expected)http://mail.foo.com
will make NGINX pass-thru to127.0.0.1:3333
https://mail.foo.com
will make NGINX pass-thru to127.0.0.1:3334
Currently I'm trying to achieve this with the following:
stream {
map $ssl_preread_server_name $name {
mail.foo.com mailcow;
}
upstream mailcow {
server 127.0.0.1:3333;
}
server {
listen 0.0.0.0:80;
proxy_pass $name;
ssl_preread on;
}
}
But as soon as I try to start NGINX, it says that port 80 is already in use. Nothing is listening on port 80. And I suspect the actual reason why NGINX is saying so is because the http
block in the configuration of each virtual host (domain) listens to port 80 too.
So, then, probably my question should be: can I listen to port 80 in both stream
and http
sections?
If "no", how would I ssl pass-thru the traffic from mail.foo.com
?