# Proxy/Redirect issue

**URL:** <https://www.ruby-forum.com/t/proxy-redirect-issue/199268>\
**Category:** NGINX\
**Created:** [November 17, 2010, 5:12pm UTC](https://www.ruby-forum.com/t/proxy-redirect-issue/199268 "2010-11-17T17:12:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![okkezSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/85f322/32.png) [@okkezSS](https://www.ruby-forum.com/u/okkezSS)\
**Post date:** [November 17, 2010, 5:12pm UTC](https://www.ruby-forum.com/t/proxy-redirect-issue/199268/1 "2010-11-17T17:12:37Z")

</div>

I have setup an nginx proxy with a couple of servers behind it, also  
running  
nginx.

For the most part everything works nicely, although I have a strange  
issue.

I have my domains setup with a wildcard CNAME record so any subdomain  
should  
work.

I have a couple of vhosts setup intitially [domain1.com](http://domain1.com) and [domain2.com](http://domain2.com)  
which  
work fine.

I have tried to redirect any requests from sub domains of these 2  
domains as  
follows:

server {  
listen 80;  
server\_name _.domain1.com;  
rewrite ^/(._)$ [http://domain1.com/$1](http://domain1.com/$1) permanent;  
}

I also tried using a check against the hostname.

The problem is the redirect works for [domain1.com](http://domain1.com), but not for  
[domain2.com](http://domain2.com),  
any request to [something.domain2.com](http://something.domain2.com) is redirected to [domain1.com](http://domain1.com).

Can anyone help resolve this?

Thanks  
Phil.

---

<div class="post-metadata">

**Author:** ![phoyce](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/bc8723/32.png) [@phoyce](https://www.ruby-forum.com/u/phoyce)\
**Post date:** [November 17, 2010, 5:29pm UTC](https://www.ruby-forum.com/t/proxy-redirect-issue/199268/2 "2010-11-17T17:29:32Z")

</div>

It’s working after all, turns out it was cached.  
The original method I had checking against the hostname within the main  
vhost declaration appears not to work though.
