phpmyadmin未加载png(图像)nginx

时间:2019-03-18 05:46:56

标签: nginx phpmyadmin

使用密码保护phpmyadmin目录之后。 png和图像未加载到网页上。这是我的nginx conf:

location ^~ /phpmyadmin/ {
    auth_basic            "Restricted";
    auth_basic_user_file  /etc/nginx/.htpasswd;
    fastcgi_pass unix:/run/php/php7.2-fpm.sock;
    include         fastcgi_params;
    fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
    fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
    }

1 个答案:

答案 0 :(得分:0)

您需要使用两个location块,一个用于PHP脚本,另一个用于资产。最好使用嵌套的location块来实现。有关详细信息,请参见this document

location ^~ /phpmyadmin/ {
    auth_basic            "Restricted";
    auth_basic_user_file  /etc/nginx/.htpasswd;

    location ~ \.php$ {
        fastcgi_pass unix:/run/php/php7.2-fpm.sock;
        include         fastcgi_params;
        fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
        fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
    }
}