我有一个具有两个域的NGINX Web服务器,它还运行phpMyAdmin。
phpMyAdmin运行正常,我可以通过下面的非https URL访问它:
public-ip-address / phpMyAdmin
这是符号链接的设置方式:
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创建了一个新的配置文件。
唯一的更改是在server
和root
路径标签中。默认休息所有。
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
块应该为您工作(至少类似的配置对我有用):
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;
}
}
[将其放置在[[之前]默认的PHP处理程序location
块中,否则默认的PHP处理程序块将优先,并且此配置将不起作用!