S
S
Stanislav2015-10-11 20:43:09
Nginx
Stanislav, 2015-10-11 20:43:09

How to make a redirect from a subdomain with a condition?

Tell me what am I doing wrong?

server {
    server_name static.site.ru
    listen ip;
    charset UTF-8;
    gzip on;
                gzip_disable "msie6";
                access_log off;
    log_not_found off;
                gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript;
                set $root_path /var/www/data/static.site.ru;
                proxy_read_timeout 1200s;
    location / {
      proxy_pass http://ip:80;
                        proxy_redirect http://ip:80/ /;
                        proxy_set_header Host $host;
                        proxy_http_version 1.1;
                        proxy_set_header Upgrade $http_upgrade;
                        proxy_set_header Connection "upgrade";
                        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                        proxy_set_header X-Real-IP $remote_addr;

      if ($request_uri !~ "^/uploads/\w+$") {
        rewrite ^(.*)$ http://www.site.ru$1 permanent;
      }
      
                }
    location /uploads/card/ {
                        alias /var/www/data/static.site.ru/uploads/card/;
                        set $disable_cache 1;
                        set $button_redirect 0;

                        #.....
                }
  }

There is a subdomain for statics with the /uploads/ directory.
It is necessary, if the request goes to the main static.site.ru or to other pages, but not from /uploads/*, then make a 301 redirect to the main domain.
Currently not working =(

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
TyzhSysAdmin, 2015-10-11
@ms-dred

Something like this :)

location /{
    rewrite ^ http://site.ru permanent;
  }
location ~ ^/(uploads)/{
    root /var/www/data/static.site.ru;
  }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question