【发布时间】:2020-10-03 06:03:54
【问题描述】:
我有一个带有两个域的 NGINX Web 服务器,它还运行 phpMyAdmin。
phpMyAdmin 工作正常,我通过以下非 https url 访问它:
公共IP地址/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 用于 Let's Encrypt 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/sn-ps/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;
【问题讨论】:
-
正确的方法取决于你的 nginx 配置。如果可以,请在您的问题中添加
domain1.com域的server配置块。 -
谢谢。我将编辑问题。
-
您能展示一下您的默认 PHP 处理程序的外观吗?通常是
location ~ \.php$ { ... }块。 -
@IvanShatsky 我在主要问题中更新了我的服务器块配置。你能看一下吗?
标签: nginx phpmyadmin symlink nginx-location