nginx与php pathinfo(TP5常用)

最近在试用fastadmin这一个框架,是由tp5进行二开后的一款框架。fastadmin里面有个代码,要获取pathinfo否则会重定向到登录页,而默认的nginx配置获取的pathinfo一直为空,就导致无法正常进入后台。

通过查找资料后,发现pathinfo是php的产物,与nginx无关。如果要让nginx把pathinfo环境变量传到php,需如下设置:

  server {
    listen 80;
    server_name _;
    access_log /data/wwwlogs/access_nginx.log combined;
    root /mnt/hgfs/vm_virtual_path/fastadmin/public;
    index index.html index.htm index.php;
    #error_page 404 /404.html;
    #error_page 502 /502.html;


    location / { 
       if (!-e $request_filename) { 
           rewrite  ^(.*)$  /index.php?s=/$1  last; 
       } 
    } 

    location /nginx_status {
      stub_status on;
      access_log off;
      allow 127.0.0.1;
      deny all;
    }
    location ~ [^/]\.php(/|$) {
      set $script $uri;
      set $path_info "";
 
      if ($uri ~ "^(.+.php)(/.+)") {
        set $script $1;
        set $path_info $2;
      }

      #fastcgi_pass remote_php_ip:9000;
      fastcgi_pass unix:/dev/shm/php-cgi.sock;
      fastcgi_index index.php;
      include fastcgi.conf;

      fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name; 
      fastcgi_param  PATH_INFO  $path_info; 
      #fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info; 

    }
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
      expires 30d;
      access_log off;
    }
    location ~ .*\.(js|css)?$ {
      expires 7d;
      access_log off;
    }
    location ~ ^/(\.user.ini|\.ht|\.git|\.svn|\.project|LICENSE|README.md) {
      deny all;
    }
    location /.well-known {
      allow all;
    }
  }

 

posted on 2024-02-22 11:02  咚..咚  阅读(19)  评论(0编辑  收藏  举报

导航