remove if from code

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

remove if from code

rnburn
I am using Nginx 1.13 and have read that using "if" is a poor solution. I
have looked through my configuration file and found one and would like to
rewrite it without the "if". Does anyone know how to rewrite this snippet?

## Execute PHP Scripts using FastCGI
        location ~ \.php(/.*)? {
    if (!-e $request_filename) {
        rewrite / /index.php last;
    }

Thanks

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,273865,273865#msg-273865

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: remove if from code

Reinis Rozitis
> Does anyone know how to rewrite this snippet?

> ## Execute PHP Scripts using FastCGI
> location ~ \.php(/.*)? {
>    if (!-e $request_filename) {
>        rewrite / /index.php last;
>    }

You can use try_files for that (
http://nginx.org/en/docs/http/ngx_http_core_module.html#try_files )

location ~ \.php$ {
    try_files $uri /index.php;
}


p.s. obviously for this location you need to add php handling also.

rr

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: remove if from code

rnburn
Thanks! I got it to work but had to put my fastcgi stuff inside.


location ~ \.php$ {
try_files $uri /index.php;

   
        # fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
        expires off;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
       fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        ## Tweak fastcgi buffers, just in case.
        fastcgi_buffer_size 256k;
        fastcgi_buffers 256 4k;
        fastcgi_busy_buffers_size 256k;
        fastcgi_temp_file_write_size 256k;
    #fastcgi_connect_timeout 300;
        #fastcgi_send_timeout 300;
        #fastcgi_read_timeout 300;
    fastcgi_param HTTPS on;
    fastcgi_param   HTTP_SCHEME         https;
   
        include fastcgi_params;
        }

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,273865,273888#msg-273888

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx