nginx - 启用身份验证网关后 phpmyadmin 500 内部服务器错误
问题描述
我在 NGINX 服务器上运行它,它运行良好,直到我启用身份验证网关。我使用 user: encryptedPassword 行生成了加密密码openssl passwd
并添加了 /etc/nginx/pma_pass 文件。我还在 /etc/nginx/sites-available/default 的 server 块中添加了 location 块。看起来像这样
location /urlpath {
auth_basic "Admin Login";
auth_basic_user_file /etc/nginx/pma_pass;
}
无论我放入什么,我都会收到身份验证提示,然后是 500。这里可能是什么问题?
这是我的整个服务器块:
server {
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
server_name www.domain domain ipaddress;
location ^~ /urlpath {
auth_basic "Admin Login";
auth_basic_user_file /etc/nginx/pma_pass;
try_files $uri $uri/ =404;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
}
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
location ~ /\.ht {
deny all;
}
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/path;
ssl_certificate_key /etc/letsencrypt/path;
include /etc/letsencrypt/path;
ssl_dhparam /etc/letsencrypt/path;
}
/var/log/nginx/error.log 最后一个条目
2020/07/04 10:57:44 [crit] 18699#18699: *530 crypt_r() failed (22: Invalid argument), client: 82.208.215.144, server: www.whatevs.info, request: "GET /path_phpadmin_is_located_at/ HTTP/1.1", host: "domain"
解决方案
总结评论中的所有讨论,解决方案是
这样一个受保护的位置应该有它自己的嵌套 PHP 处理程序并使用
^~
位置修饰符(以避免像下面的位置/urlpath/index.php
捕获的请求location ~ \.php$ { ... }
):location ^~ /urlpath { auth_basic "Admin Login"; auth_basic_user_file /etc/nginx/pma_pass; try_files $uri $uri/ =404; location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/var/run/php/php7.2-fpm.sock; } }
密码文件应包含格式为的行,
<user_name>:<hashed_password>
并且该行内不应包含任何额外的空格。
推荐阅读
- go - Go 项目不从 github 拉取导入更新
- python - Tried installing FastAi but I got "ERROR: No matching distribution found for torchvision>=0.7"
- c - Using main(int arc, char *argv[])?
- hyperlink - How to include the last word of hyperlink text in TRichEdit in the blue, underline format of the rest?
- c - Function return via pointer doesn't work correctly
- javascript - NodeJS createWriteStream JavaScript heap out of memory
- reactjs - React Incorrect render when combine withRouter/withStyles and mobx's observer
- lambda - 继续通过式程序
- reactjs - react-toastify showing twice with SSR
- javascript - Asp.net 部分视图 - 单击后设置 html 和 css - 不改变它的状态