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 supposed to write something like this

    location !-f {
        proxy_pass         http://lst207.b.ls1.ru:8000/;
        }

# static content
location ~* ^.+\.(jpg|jpeg|gif|css|js|ico|rar|gz|zip|pdf|tar|bmp|xls|doc|swf|mp3|avi|png|htc|txt|htc|flv)$ {
    #root         "$document_root$";
    access_log   off;
    expires      7d;
} 

But seem "-f" flag doesn't work

share|improve this question
    
I just thought may be error_page 404 = /index.php; could help me. if it doesn't send 404 header –  user45697 Nov 19 '10 at 12:56

3 Answers 3

up vote 2 down vote accepted

try_files is designed for just this scenario.

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

location ~* \.(jpg|jpeg|gif|css|js|ico|rar|gz|zip|pdf|tar|bmp|xls|doc|swf|mp3|avi|png|htc|txt|htc|flv)$ {
    access_log   off;
    expires      7d;
} 

location @fallback {
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP  $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

    proxy_pass http://lst207.b.ls1.ru:8000/;
}
share|improve this answer
    
thanks a lot for your answer. a little remark proxy_pass lst207.b.ls1.ru:8000; - without a slash at the ending. and I don't know why but it doesn't work for me though it should work. –  user45697 Nov 19 '10 at 16:39

If the first line of your index.php (in the comment) is: header("HTTP/1.0 302 Found"); then it should send a 302 instead of a 404 to the browser, but I'm thinking in apache terms, rather than nginx.

The second line could be something like: header("Location: <redirect location>");

Might that be enough?

share|improve this answer
location ~* ^.+.(jpg|jpeg|gif|css|js|ico|rar|gz|zip|pdf|tar|bmp|xls|doc|swf|mp3|avi|png|htc|txt|htc|flv)$ {
    root /the/location/of/static;
    access_log off;
    expires 7d;
    }
location / {
    proxy_set_header X-Real-IP  $remote_addr;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_pass http://lst207.b.ls1.ru:8000/;
    }

Does this work for you???

share|improve this answer
    
A location does not require the file to exist, so that won't work. –  Martin Fjordvald Nov 19 '10 at 14:07
    
Ahhhh.. for what reason is this required ??? i mean serve your dynamic content from apache and static from nginx or Why not just use the caching that nginx provides...or varnish..??? it seems kind of indirect for your problem.. –  Arenstar Nov 19 '10 at 17:59

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.