我下载了官方phpmyadmin泊坞窗图片(https://store.docker.com/community/images/phpmyadmin/phpmyadmin)。一切都好。
对我来说只有一个问题:访问网址为http://localhost
,我想成为http://localhost/phpmyadmin
。
我做了一些研究,发现密钥在/etc/nginx.conf
,由supervisord调用。以下是/etc/nginx.conf
中的摘录:
server {
listen 80 default_server;
server_name _;
root /www;
index index.php index.html index.htm;
charset utf-8;
if ($request_method !~ ^(GET|HEAD|POST)$ ) {
return 405;
}
location / {
try_files $uri $uri/ =404;
}
location ~* .(jpg|jpeg|png|gif|ico|css|js)$ {
expires 365d;
}
location ~ \.php$ {
fastcgi_intercept_errors on;
fastcgi_pass unix:/var/run/php/php-fpm.sock;
# regex to split $uri to $fastcgi_script_name and $fastcgi_path
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# Check that the PHP script exists before passing it
try_files $fastcgi_script_name =404;
# Bypass the fact that try_files resets $fastcgi_path_info
# see: https://trac.nginx.org/nginx/ticket/321
set $path_info $fastcgi_path_info;
fastcgi_param PATH_INFO $path_info;
fastcgi_read_timeout 600;
fastcgi_buffering off;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
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_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REQUEST_SCHEME $scheme;
fastcgi_param HTTPS $https if_not_empty;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
}
location ~ /\. {
deny all;
}
location ~ /(libraries|templates) {
deny all;
}
}
是否有人知道如何修改此nginx.conf
以使访问网址变为http://localhost/phpmyadmin
?
答案 0 :(得分:1)
我不建议在 Nginx 中解决这个问题。这可能容易出错,特别是如果有人进行反向代理。
官方的 phpmyadmin 镜像似乎是基于 Apache 的。
很遗憾,从 2021 年开始,无法从 /phpmyadmin 提供 phpmyadmin
所以你必须自己构建额外的层:
FROM phpmyadmin
RUN mv /var/www/html /var/www/phpmyadmin
RUN mkdir -p /var/www/html
RUN mv /var/www/phpmyadmin /var/www/html/phpmyadmin
或者您可以使用对您有相同作用的图像:
laimison/phpmyadmin:latest
题外话:如果有人问反向代理什么配置就够了:
location /phpmyadmin {
proxy_pass http://pma:80;
proxy_set_header Host $http_host;
break;
}
就是这样。
答案 1 :(得分:0)
您可以尝试使用alias
directive
location / {
location /phpmyadmin/ {
alias /www;
...
这将提供相同的根文件,但仅适用于网址http://localhost/phpmyadmin
关于docker,这意味着您需要使用以FROM phpmyadmin/phpmyadmin:4.6
开头的Dockerfile构建自己的图像,并复制nginx.conf
的修改版本,有点像3bdigital/docker-phpmyadmin
repo
OP faraday选择了更简单的方法:
使用ubuntu作为基本映像并安装phpmyadmin来构建一个docker镜像 它在安装后在
http://localhost/phpmyadmin
下工作。