Welcome! Log In Create A New Profile

Advanced

How replace if statement and optimize

Posted by nenad 
How replace if statement and optimize
August 04, 2012 08:27AM
Can someone tell me how I can replace the if with try_files that it work as before? Can I do some more optimization here (on production I deactivated access_log)?

server {
listen *:80;
server_name p.domain.com p1.domain.com p2.domain.com;

access_log /srv/log/nginx/p-kflirt/access.log;
error_log /srv/log/nginx/p-kflirt/error.log;

if ($allow_visit = no) {
rewrite ^ /not_available.html break;
}

location / {
root /srv/data/p-kflirt;
proxy_store on;
proxy_store_access user:rw group:r all:r;
proxy_temp_path /tmp/image;

# if local server don't has the photo take it from the other
if (!-f $request_filename)
{
proxy_pass http://10.10.10.121:8080;
}
index index.html index.htm;
expires max;
add_header Cache-Control public;
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
Re: How replace if statement and optimize
August 04, 2012 12:33PM
I still consider myself new to nginx, so hopefully someone else will reply with better feedback, but, this is how I would do it:

location / {
root /srv/data/p-kflirt;
proxy_store on;
proxy_store_access user:rw group:r all:r;
proxy_temp_path /tmp/image;

# if local server don't has the photo take it from the other
try_files $uri $uri/ @photoproxy;

index index.html index.htm;
expires max;
add_header Cache-Control public;
}

location @photoproxy {
proxy_pass http://10.10.10.121:8080;
}

I'm not sure what other options there are, but fjordvald warned against using it because of the extra stat() call on each page load here:

http://blog.martinfjordvald.com/2011/06/why-path-info-is-the-worst-php-feature-since-register-globals/
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 284
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready