Nginx 在网站子目录中设置phpMyAdmin
我有一个带有两个域的nginxweb服务器,它还运行phpMyAdmin phpMyAdmin工作正常,我通过以下非https url访问它: 公共ip地址/phpMyAdmin 以下是符号链接的设置方式:Nginx 在网站子目录中设置phpMyAdmin,nginx,phpmyadmin,symlink,nginx-location,Nginx,Phpmyadmin,Symlink,Nginx Location,我有一个带有两个域的nginxweb服务器,它还运行phpMyAdmin phpMyAdmin工作正常,我通过以下非https url访问它: 公共ip地址/phpMyAdmin 以下是符号链接的设置方式: sudo ln -s /usr/share/phpmyadmin/ /var/www/html 有没有办法将phpMyAdmin指向网站的子目录 例如,我想通过访问以下URL访问phpMyAdmin登录页面: domain1.com/phpMyAdmin/ 我怎样才能做到这一点?doma
sudo ln -s /usr/share/phpmyadmin/ /var/www/html
有没有办法将phpMyAdmin指向网站的子目录
例如,我想通过访问以下URL访问phpMyAdmin登录页面:
domain1.com/phpMyAdmin/
我怎样才能做到这一点?domain1.com已启用https。因此,它还可以保护我的phpMyAdmin登录
服务器块与NGINX的默认块相同。我通过将其复制到/etc/NGINX/sites available
文件夹中的domain.com,创建了一个新的配置文件
唯一的更改是服务器
和根
路径标记。Rest一切都是默认的
server domain1.com www.domain1.com;
root /var/www/domain1.com/html/
我正在使用certbot来加密SSL证书。我的服务器块配置在下面共享:
# Server Block Config for domain1.com
server {
root /var/www/domain1.com/html;
# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;
server_name domain1.com www.domain1.com;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
# try_files $uri $uri/ =404;
try_files $uri $uri/ /index.php?q=$uri&$args;
}
# pass PHP scripts to FastCGI server
#
location ~ \.php$ {
include snippets/fastcgi-php.conf;
#
# # With php-fpm (or other unix sockets):
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/domain1.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/domain1.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = www.domain1.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = domain1.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
listen [::]:80;
server_name domain1.com www.domain1.com;
return 404; # managed by Certbot
}
/etc/nginx/snippets/fastcgi-php.conf的内容:
# 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: http://trac.nginx.org/nginx/ticket/321
set $path_info $fastcgi_path_info;
fastcgi_param PATH_INFO $path_info;
fastcgi_index index.php;
include fastcgi.conf;
下面是应该适用于您的
位置
块(至少类似的配置适用于我):
location~*^/phpmyadmin(?/*)?{
别名/usr/share/phpmyadmin/;
index.php;
try_files$pmauri$pmauri/=404;
位置~\.php${
包括fastcgi.conf;
fastcgi_index.php;
fastcgi_参数脚本_文件名$document_根$pmauri;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
}
将其放在默认PHP处理程序
位置
块之前,否则默认PHP处理程序块将优先,此配置将不起作用 您只需将另一个符号链接添加到domain1.com根目录,同时保持其他所有内容不变,就像您为默认域所做的那样
sudo ln-s/usr/share/phpmyadmin//var/www/domain1.com/html
我错过什么了吗?
我是在寻找另一个问题的解决方案()时来到这个线程的,但是由于您已经在为您通过IP访问的站点使用phpmyadmin的符号链接,您可以对任何域执行相同的操作。正确的方法取决于您的nginx配置。如果可以,请将
domain1.com的server
配置块添加到您的问题中。谢谢。我将编辑这个问题。你能展示一下你的默认PHP处理程序的外观吗?通常是location~\.php${…}
block.@IvanShatsky我已经在主要问题中更新了我的服务器块配置。你能看一下吗?那么这个位置块可以在domain1.com/phpmyadmin
上访问吗?我需要编辑现有的符号链接吗?@ShoumikDas在domain1.com/phpMyAdmin
下,如您在问题中所述(区分大小写)。要使复选框不区分大小写,请将~
替换为~*
。此配置完全不需要符号链接。我在sudo nginx-t
中遇到此错误:nginx:[emerg]“fastcgi\u index”指令在/etc/nginx/sites enabled/domain1.com:26 nginx:configuration file/etc/nginx/nginx.conf测试中重复失败
@ShoumikDas可能它已经存在于您的代码片段/fastcgi php.conf
中?如果是,且其值为index.php
,则从该位置
块中删除相应的行。@ShoumikDas如果仍然无效,请将此文件的内容也添加到您的问题中。
location ~* ^/phpmyadmin(?<pmauri>/.*)? {
alias /usr/share/phpmyadmin/;
index index.php;
try_files $pmauri $pmauri/ =404;
location ~ \.php$ {
include fastcgi.conf;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$pmauri;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
}