fpm和Nginx

分享于 

2分钟阅读

互联网

  简体

问题:

我尝试使用Nginx运行PHP应用程序,重写URL可以正常工作,但查询字符串不能传递给PHP文件,

nginx-site.conf:


server {


 root /var/www/html;



 include /etc/nginx/default.d/.conf;



 index index.php index.html index.htm;



 client_max_body_size 30m;



 server_tokens off;



 location / {


 index index.html index.htm index.php;


 try_files $uri $uri/ @extensionless-php;


 }



 location ~* .(?:ico|css|js|gif|jpe?g|png|svg|woff)$ {


 expires 30d;


 add_header Pragma public;


 add_header Cache-Control "public";


 }



 location ~ .php$ {


 fastcgi_param HTTP_PROXY "";


 fastcgi_pass 127.0.0.1:9000;


 fastcgi_index index.php;


 include fastcgi.conf;


 }



 location @extensionless-php {


 if ( -f $document_root$uri.php ) {


 rewrite ^ $uri.php last;


 }


 fastcgi_pass 127.0.0.1:9000;


 include fastcgi.conf;


 }



 location ~* /includes/(.+).php$ {


 deny all;


 }


}




答案1:

替代:


location / {


 index index.html index.htm index.php;


 try_files $uri $uri/ @extensionless-php;


}



使用:


location / {


 index index.html index.htm index.php;


 try_files $uri $uri.php =404;


}



如果查询参数不能工作,请尝试:


try_files $uri $uri.php$is_args$args =404;



也应该删除location @extensionless-php



Nginx  
相关文章