I'm a bit stuck on this one and any assistance would be amazing. I'm very much an Nginx noob.
We have an existing Nginx setup with lots of redirections already configured.
I'm trying to only redirect one subdomain in Nginx to an external url, however no matter what I try it redirects all subdomains.
I've reviewed our existing configs to get some understanding of how things are setup but the life of me I just can't work this one out and all the search results I seem to find are for redirecting all subdomains or sub sites not for redirecting just one subdomain of many.
This subdomain didn't have an existing config and I've had to create one (copy one of our others and edit it) it looks like previously the subdomain was configured under a catch all.
Example:
I need https://foo-bar.test.com.au to redirect to https://externalURL.com
However I don't want https://other-site.test.com.au to redirect to https://externalURL.com
This is the current config
server {
server_name foo-bar.test.com.au;
rewrite ^ https://externalURL.com;
root /opt/nginx-static/foo-bar;
}
server {
listen 443 ssl http2;
server_name foo-bar.test.com.au;
rewrite ^/(.*)$ https://externalURL;
ssl_certificate /etc/ssl/foo-bar.crt;
ssl_certificate_key /etc/ssl/foo-bar.key;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_session_timeout 30m;
root /opt/nginx-static/foo-bar;
location / {
root /opt/nginx-static/foo-bar;
index index.html foo-bar.html;
autoindex on;
}
}