Nginx as a forward proxy (kind of)

Hi

I am very new to nginx and have a quick question.
I am using nginx to basically redirect certain websites through another
proxy. I am using DNS to resolve *.domain.com to the IP address of
nginx server.
I am able to get it to work with www.domain.com (see sample config
below) but would like it to redirect any subdomain (wildcard) to
corresponding subdomain. Any way to do this without having a similar
config for each subdomain?

server {
listen 192.168.1.80:443;
server_name *.domain.com;
ssl on;
ssl_certificate /tmp/test_cert.crt;
ssl_certificate_key /tmp/test_cert.key;
access_log /var/log/nginx/log/www.example.access.log main;
error_log /var/log/nginx/log/www.example.error.log;
location / {
proxy_pass https://www.domain.com;
}
}

On Sun, Sep 14, 2014 at 12:28:30AM +0200, Sam J. wrote:

Hi there,

I am very new to nginx and have a quick question.
I am using nginx to basically redirect certain websites through another
proxy. I am using DNS to resolve *.domain.com to the IP address of
nginx server.
I am able to get it to work with www.domain.com (see sample config
below) but would like it to redirect any subdomain (wildcard) to
corresponding subdomain. Any way to do this without having a similar
config for each subdomain?

http://nginx.org/r/proxy_pass

See the part mentioning variables.

Note that nginx is a reverse proxy, which pretty much means that you
control the upstream(s). It can act sort-of like a normal proxy in your
controlled environment; but if you want a proxy, get a proxy and you’ll
be happier.

And because you use ssl, to keep the browser happy you will want to make
sure that your certificate fits whatever hostname the browser
requests. (Or configure the browser not to care about man-in-the-middle
attacks.)

f

Francis D. [email protected]