问题
I'm rolling my own mvc framework starting with a front controller, which is working - all requests go through /index.php, which is loading bootstrap files eg router.php.
However, $_GET isn't working, so my router.php file isn't working. My URL scheme will simply be /controller/view with .php omitted, but as yet I can't change URLs because I can't $_GET the url to pass to router.php (to load the correct controller and view).
I have searched everywhere for solutions and found this similar post on stackoverflow, but it's recommended fix doesn't work for me: https://serverfault.com/questions/231578/nginx-php-fpm-where-are-my-get-params
Here's my nginx.conf:
server {
listen 80;
server_name mvcapp;
#Remove Trailing Slash '/'
rewrite ^/(.*)/$ /$1 permanent;
root /usr/local/var/www/mvcapp/public;
index index.php;
location / {
# Neither of the below 2 lines work
#try_files $uri $uri/ /index.php?$query_string;
try_files $uri $uri/ /index.php?$args;
}
#proxy Non-static requests to nginx
location ~ \.php$ {
# Include the default fastcgi_params file included with Nginx
include /usr/local/etc/nginx/fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
# Pass to upstream PHP-FPM;
fastcgi_pass 127.0.0.1:9000;
}
}
My knowledge of php-fpm is very weak - so perhaps I am missing a fastcgi_param?
What do you see wrong?
(thanks)
回答1:
If you want to pass the URI as a get parameter, do something like this:
try_files $uri $uri/ /index.php?$request_uri;
Your index.php
will see as if you used index.php?/controller/view
来源:https://stackoverflow.com/questions/18689959/nginx-php-fpm-php-works-except-cannot-use-get