Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

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;
    }
}
share|improve this answer
    
Will this account for links like m.imax.com/mobile/main? How would I account for that? –  kkubasik Oct 31 '10 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 –  Martin Fjordvald Oct 31 '10 at 3:05
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.