为什么 nginx 别名在 .php 文件上返回 404?

为什么 nginx 别名在 .php 文件上返回 404?

此配置有效:

location /phpmyadmin {
   root /usr/share/;
   index index.php index.html index.htm;
   location ~ ^/phpmyadmin/(.+\.php)$ {
           try_files $uri =404;
           root /usr/share/;
           fastcgi_pass unix:/var/run/php5-fpm.sock;
           fastcgi_index index.php;
           fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
           include /etc/nginx/fastcgi_params;
   }
   location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
           root /usr/share/;
   }
}

但这会在每个 .php 文件上返回 404(而 .css/.txt 工作正常):

location /pma {
    alias /usr/share/phpmyadmin;
    index index.php index.html index.htm;

    location ~ ^/pma/(.+\.php)$ {
            alias /usr/share/phpmyadmin/$1;
            try_files $uri =404;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            include /etc/nginx/fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

    }

    location ~* ^/pma/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
            alias /usr/share/phpmyadmin/$1;
    }
}

错误日志为空。

答案1

有一个问题目录aliastry_files

您可能需要考虑使用隐藏在内部重写后面的旧配置:

location /pma {
    rewrite ^/pma(.*)$ /phpmyadmin$1;
}
location /phpmyadmin {
    internal;
    ...
}

相关内容