T
T
Trave2010-11-29 06:57:38
Nginx
Trave, 2010-11-29 06:57:38

Proxy *.example.com to *.localTLD?

It is necessary to proxy http requests *.example.com to *.localTLD, and if somedomain.localTLD does not resolve, you need to throw it on the default page (I think this can be done through the error page for 502 Bad gateway).
How to make such a tricky proxy with undefined domains in nginx, lighttpd, apache?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Servn, 2010-11-29
@Trave

Then you can write in

server_name default;
if ($host ~* (.*).example.com) {
    set $host_prefix $1;
    rewrite ^.*$ http://$host_prefix.localTLD/ permanent;
}

S
Servn, 2010-11-29
@Servn

For Nginx something like this

server {
    listen 0.0.0.0:80;
    server_name www.example.com

    location / {
        # Proxy
        proxy_pass http://somedomain.localTLD;
        # Catch errors for processing before issuing to the client
        proxy_intercept_errors on;

        # additional options if needed
        # for example, if you are proxying to IP, you usually need to specify the host
        # proxy_set_header Host 'somedomain.localTLD';
        # Or
        # proxy_read_timeout 60;
    }
    location /pages/ {
        root /var/www/;
    }

    # Further error handling
    error_page 502 503 504 /50x.html;
    # Or if you need to answer 200 and give another page then
    # error_page 502 503 504 =200 /pages/page.html;
}

By proxying
wiki.nginx.org/HttpProxyModule
By errors
wiki.nginx.org/HttpCoreModule#error_page

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question