Re: rewrite subdomain

Vladislav Vorobiev mymir.org googlemail.com
25 08:49:49 MSK 2010


> .
>
>    .
>     
> http://domain.com/catalog/firm1
> http://domain.com/catalog/firm2
>
>     ,        
> http://firm1.domain.com/
> http://firm2.domain.com/
>
>     server_name *.domain.com     :
>
> if ($host ~* ^(+)\.domain.com$) {
>        set $subdomain $1;
>        rewrite ^ /index.php/enterprises/$subdomain last;
>        break;
> }
>
>        .
>     ,   ,         :
>
> server {
>    listen     80;
>    server_name ~^([^.]+)\.domain\.com$;
>    set $subdomain $1;
>    server_tokens off;
>
>    send_timeout 120;
>
>    root      /usr/local/www/nginx;
>    index      index.php;
>    fastcgi_index  index.php;
>
>    rewrite        \.(js|ico|gif|jpg|png|css|flv)$     /$uri break;
> #   rewrite ^ /index.php$uri$subdomain break;
>    rewrite        /             /index.php$uri$subdomain break;
>
>    location ~ \.php {
>        include fastcgi_params;
>        keepalive_timeout 0;
>        expires   30d;
>        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
>        fastcgi_pass  127.0.0.1:9000;
>    }
>
> }
>
>      -  .
>
> debug :
> 2010/03/24 20:16:28 52531#0: *10862 "/" matches "/", client: 89.252.34.110, server: ~^([^.]+)\.domain\.com$, request: "GET / HTTP/1.1", host: "firm1.domain.com"
> 2010/03/24 20:16:28 52531#0: *10862 rewritten data: "/index.php/firm1", args: "", client: 89.252.34.110, server: ~^([^.]+)\.domain\.com$, request: "GET / HTTP/1.1", host: "firm1.domain.com"
>
> nginx -V
> nginx version: nginx/0.8.33
> configure arguments: --prefix=/usr/local/etc/nginx --with-cc-opt='-I /usr/local/include' --with-ld-opt='-L /usr/local/lib' --conf-path=/usr/local/etc/nginx/nginx.conf --sbin-path=/usr/local/sbin/nginx --pid-path=/var/run/nginx.pid --error-log-path=/var/log/nginx-error.log --user=www --group=www --http-client-body-temp-path=/var/tmp/nginx/client_body_temp --http-proxy-temp-path=/var/tmp/nginx/proxy_temp --http-fastcgi-temp-path=/var/tmp/nginx/fastcgi_temp --http-log-path=/var/log/nginx-access.log --with-http_dav_module --with-http_flv_module --with-http_geoip_module --with-http_gzip_static_module --with-http_perl_module --with-http_realip_module --with-http_stub_status_module --with-pcre
>
>         ,   .  .   .
>
> Posted at Nginx Forum: http://forum.nginx.org/read.php?21,67477,67477#msg-67477
>


 ,  .      proxy_pass

server {
server_name *.mydomain.net;
listen 80;

location / {

               set $name de;
               if ($host ~ ^(.+).mydomain.net$) {
                   set  $name $1;
               }
        proxy_set_header REMOTE_ADDR    $remote_addr;

        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_pass
        http://localhost:8080/$name.mydomain.net:80/$name/$uri?$query_string;
   }
}


-- 
Best Regards
Vlad Vorobiev


nginx-ru