I have a nginx server which I use as a proxy. I want to have all requests forwarded as normal http requests, expect request to api.mydomain.org, those request I want to run with ssl/https.
This works fine with the following:
server { listen 80; server_name api.mydomain.org; return 301 https://api.mydomain.org$request_uri; } server { listen 443; server_name api.mydomain.org; location / { proxy_pass http://backend; proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504; proxy_redirect off; proxy_buffering off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto https; } ssl on; ssl_certificate /etc/nginx/ssl/api.mydomain.org/server.crt; ssl_certificate_key /etc/nginx/ssl/api.mydomain.org/server.key; }
However, this will redirect all request to subdomains which are not specifically specified/qualified. E.g. a.mydomain.org or b.mydomain.org are sent to https://api.mydomain.org.
How do I configure this?