0

I want to take m.example.com and direct those requests to example.com/mobile/ with nginx. (The same nginx sever will be serving example.com)

Can someone help me with the config I would need? I can post my nginx.conf if needed, but I assume its something like:

location / { rewrite /([^/] +) /mobile/$1 break; proxy_pass http://127.0.0.1; }

Am I in the right ballpark?

1 Answer 1

1

You should use a server block for this to allow Nginx to use it's hash table lookup.

server {
    server_name m.example.com;

    location / {
        rewrite ^ http://example.com/mobile$request_uri permanent;
    }

    location /mobile {
        rewrite ^ http://example.com$request_uri permanent;
    }
}
2
  • Will this account for links like m.imax.com/mobile/main? How would I account for that?
    – kkubasik
    Oct 31, 2010 at 0:14
  • Edited the code example. Now it will rewrite m.example.com/mobile/main and m.example.com/main to example.com/mobile/main Oct 31, 2010 at 3:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .