subdomena nginx i domena rewrite w proxy pass

Potrzebuję tych dwóch typów przeróbek:

subdomain.domain.com => domain.com/website/subdomain

otherdomain.com => domain.com/userdomain/otherdomain.com

Mój problem polega na tym, że chcę, aby użytkownik zobaczył subdomain.domain.com i otherdomain.com, A Nie wersję przekierowaną. Mój obecny przepisać w nginx działa, ale URL użytkownika pokazuje przepisać, i chcę, aby to było przejrzyste dla użytkownika, jakieś pomysły?:

upstream domain_server { server localhost:8000 fail_timeout=0; }     

server {
        listen  80;
        root  /var/www/domain.com;

        server_name domain.com ~^(?<subdomain>.*)\.domain\.com$ ~^(?<otherdomain>.*)$;
        if ( $subdomain ) {
                rewrite ^ http://domain.com/website/$subdomain break;
        }
        if ( $otherdomain ) {
                rewrite ^ http://domain.com/userdomain/$otherdomain break;
        }

        location / {
                proxy_redirect off;
                proxy_buffering off;
                proxy_set_header Host $http_host;
                proxy_set_header X-forwarded-for $proxy_add_x_forwarded_for;
                if (!-f $request_filename) {
                        proxy_pass http://domain_server;
                        break;
                }
        }

}
Author: pyramation, 2012-05-10

1 answers

Dzięki nginx w ogóle nie musisz przepisywać.

upstream domain_server { server localhost:8000 fail_timeout=0; }

proxy_set_header Host domain.com;
proxy_set_header X-forwarded-for $proxy_add_x_forwarded_for;

server {
    listen  80 default_server;

    location / {
        proxy_pass http://domain_server/userdomain/$http_host;
    }
}

server {
    listen  80;
    server_name domain.com;

    root  /var/www/domain.com;

    location / {
        try_files $uri @backend;
    }

    location @backend {
        proxy_pass http://domain_server;
    }
}

server {
    listen  80;
    server_name ~^(?<subdomain>.+)\.domain\.com$;

    location / {
        proxy_pass http://domain_server/website/$subdomain$request_uri;
    }
}
 24
Author: VBart,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-01-22 23:38:10