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; } }
分类:
PHP
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· 上周热点回顾(2.17-2.23)
· 如何使用 Uni-app 实现视频聊天(源码,支持安卓、iOS)
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章