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 have a nginx server serving http://gork.com. I have 2 directories that are being served (http://gork.com/foo and http://gork.com/api), all other requests need to be redirected, for example: http://gork.com/michael -> http://example.com/michael

How can this be accomplised? Below is what I have tried (along with some similar variants), but the server timeouts (as if no location blocks are 'running'), how can this be done? Why am I getting a timeout?

root /home/michael/www;
index index.php index.html;

proxy_redirect  off;
proxy_set_header Host             $http_host;
proxy_set_header X-Forwarded-For  $remote_addr;

location /forms {
    root /var/www/html;
    try_files $uri $uri/ @proxy;
}

location /m {
    root /var/www/html;
    try_files $uri $uri/ @proxy;
}

location /api {
    proxy_pass  http://127.0.0.1:8080;
}

location / {
    try_files $uri $uri/ @external;
}

location ~ \.php$ {
   proxy_pass   http://127.0.0.1:8080;
}

location @external {
    rewrite ^(.*) http://www.example.com$1 permanent;
}

location @proxy {
    proxy_pass  http://127.0.0.1:8080;
}

location ~ /\.ht {
    deny  all;
}
share|improve this question
1  
Where did you put these location blocks? Post the entire of the configuration file. –  quanta Nov 11 '11 at 2:07
    
@quanta, I edited my original question with all of the location blocks. –  mmattax Nov 11 '11 at 2:26
    
Is it in server block? Which URL did you try? –  quanta Nov 11 '11 at 2:33
    
Yes, this is in a .conf that is used in 2 server blocks (HTTPS and HTTP). All requests timeout with the above settings. If I remove the @external, all is fine (/forms, /m, /api), but the redirect obviously does not work. –  mmattax Nov 11 '11 at 2:44
    
Your config looks fine. Insert an error_log directive and take a look at this. –  quanta Nov 11 '11 at 3:38

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.