环境:
CentOS 7.4 x64
Nignx 1.14
PHP 7.2.6
配置文件 Nginx.conf 根/root 为 /web/public, phpmyadmin 放在 /web/phpmyadmin,
location /phpmyadmin/ {
alias /web/phpmyadmin/;
index index.php index.html index.htm;
location ~ ^/phpmyadmin/(.+?\.php)(/.*)?$ {
alias /web/phpmyadmin/;
fastcgi_split_path_info ^(.+?\.php)(/.*)?$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /web/phpmyadmin/$fastcgi_script_name;
include fastcgi_params;
}
location ~ ^/phpmyadmin/(.+)\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)(/.*)?$ {
alias /web/phpmyadmin/;
expires 6d;
}
}
配置代码如上,总是提示 404 错误。
Nignx 错误信息: FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream
使用 root 设置的话就没有问题,无语了。
location /phpmyadmin/ {
root /web;
index index.php index.html index.htm;
location ~ ^/phpmyadmin/(.+?\.php)(/.*)?$ {
root /web;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ ^/phpmyadmin/.*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico|js|css)$ {
root /web;
expires 7d;
}
}
非正则,且路径对应指令path值的最后一部分,如:
这个是建议使用root的(官方最佳实践)
正则路径,表达式里需要带上匹配组,且应该被alias引用,如: