http -> https redirection, with a twist?
António P. P. Almeida
appa at perusio.net
Wed Feb 29 02:20:13 UTC 2012
On 29 Fev 2012 03h07 CET, brad at shub-internet.org wrote:
> Folks,
>
> I've been trying to figure out how to set this up, I've gone through
> as much of the web site and wiki as I can, and I've searched on the
> net as much as I can. I'm still stumped.
>
> We have several different servers that we want to redirect from port
> 80, and most of them will land on the same machine but on port 443.
> However, one of those needs to land on a different port -- 8443.
>
> If this were a simple redirect without a twist, I'd probably go with
> something like the example shown at
> <http://serverfault.com/questions/192382/nginx-redirect-all-traffic/263091#263091>,
> although because I'm doing a one-to-one mapping of multiple FQDNs,
> and not just mapping a bunch of FQDNs to a single name, I'd be
> inclined to use an example more like this:
>
> server { server_name a.domain.com c.domain.com d.domain.com; # you
> can serve any number of redirects from here... listen 80; rewrite ^
> https://$host$1$uri$is_arg$args permanent; }
>
> But with the single server definition listening to port 80 on all
> interfaces, I don't see how to make that one FQDN get redirected to
> port 8443 instead of port 443.
>
> Am I missing something obvious here?
If I understood correctly. Try:
server {
server_name a.domain.com c.domain.com d.domain.com;
listen 80;
return 301 https://$host:8443$request_uri;
}
You can use a wildcard to match all subdomains. Perhaps it suits you:
server {
server_name *.domain.com; # this is more generic [1]
listen 80;
return 301 https://$host:8443$request_uri;
}
--- appa
[1] http://nginx.org/en/docs/http/server_names.html#wildcard_names
More information about the nginx
mailing list