A
A
Alexander2018-05-06 22:18:30
PHP
Alexander, 2018-05-06 22:18:30

Single entry point on nginx+php-fpm?

I need any request to be redirected to index.php. I try this (taken from some site):

server {
        server_name 192.168.1.20;
        listen 80;
        root /home/abc/www;
        index index.php;
        charset utf-8;

        location / {
            try_files $uri $uri/ /index.php?$args;
        }

        location ~ \.php$ {
            try_files $uri =404;
            fastcgi_pass unix:/home/abc/service/php-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        }   
    }

With this config, if I put the info.php file next to index.php and request it in the browser (192.168.1.20/info.php), then it is executed. And it should have kicked off on index.php.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
ky0, 2018-05-06
@ky0

Everything is logical - if it info.phpexists, it will not reach the try_filesfirst location /index.php?$args, the request will move to the second location and be processed in the usual way.
If you want all your php files to be redirected to index.php- modify accordingly try_filesor just add a rewrite to /.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question