ArchLinux 配置 phpMyAdmin

nginx 中配置 phpMyAdmin, 照着教程 phpMyAdmin-ArchWiki, subdomainsubdirectory using symlink 模式都能配置成功, 但是 subdirectory using alias 模式配置不能正常访问,

# phpmyadmin subdirectory using alias
 location /phpmyadmin {
         alias /usr/share/webapps/phpMyAdmin;
         # Optionally set separate access and error logs for phpMyAdmin
         access_log /var/log/nginx/phpmyadmin_access.log;
         error_log /var/log/nginx/phpmyadmin_error.log;
         index   index.php;  
         try_files $uri $uri/=404;
         # Deny some static files
         location ~ ^/phpmyadmin/(README|LICENSE|ChangeLog|DCO)$ {
                 deny all;
         }
         # Deny .md files
         location ~ ^/phpmyadmin/(.+\.md)$ {
                 deny all;
         }
         # Deny some directories
         location ~ ^/phpmyadmin/(doc|sql|setup)/ {
                 deny all;
         }
         #FastCGI config for PhpMyAdmin
         location ~ /phpmyadmin/(.+\.php)$ {
                 fastcgi_param  SCRIPT_FILENAME /usr/share/webapps/phpMyAdmin/$1;
                 fastcgi_pass   unix:/run/php-fpm/php-fpm.sock;
                 fastcgi_index  index.php;
                 include        fastcgi.conf;
         }
 }
# 浏览器访问 http://localhost/phpmyadmin/index.php
File Not Found  

查看nginx错误日志

# vim /var/log/nginx/phpmyadmin_error.log
2017/04/21 14:57:09 [error] 4691#4691: *43 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 127.0.0.1, server: localhost, request: "GET /pma/index.php HTTP/1.1", upstream: "fastcgi://unix:/run/php-fpm/php-fpm.sock:", host: "localhost"  

原因分析

根据错误信息应该是php文件路径错误引起, 由于fastcgi.conf中也的定义了 SCRIPT_FILENAME 覆盖了 fastcgi_param SCRIPT_FILENAME /usr/share/webapps/phpMyAdmin/$1;

# vim /etc/nginx/fastcgi.conf
fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name; # override  
fastcgi_param  QUERY_STRING       $query_string;  
fastcgi_param  REQUEST_METHOD     $request_method;  
fastcgi_param  CONTENT_TYPE       $content_type;  
fastcgi_param  CONTENT_LENGTH     $content_length;  
....

fastcgi_param SCRIPT_FILENAME /usr/share/webapps/phpMyAdmin/$1; 移动到 include fastcgi.conf 后面, 问题解决

         location ~ /phpmyadmin/(.+\.php)$ {
                 fastcgi_pass   unix:/run/php-fpm/php-fpm.sock;
                 fastcgi_index  index.php;
                 include        fastcgi.conf;
                 fastcgi_param  SCRIPT_FILENAME /usr/share/webapps/phpMyAdmin/$1;
         }