是否有适当的方法来指定应在 nginx 中将虚拟目录的哪些后端内容发送到?目前,我有一个使用 tomcat 和 PHP-FPM 运行 nginx 的站点,其中默认情况下将请求发送到 tomcat,我想添加一个名为 dbadmin 的虚拟目录(该目录的内容存储在磁盘上完全不同的位置),其中包含 phpmyadmin请求被发送到 PHP-FPM 套接字。
我当前的配置(conf.d/default.conf):
server {
listen 80 default_server;
server_name mydomain.com;
root /opt/apache-tomcat/webapps;
# cache statis files for 1 month
location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ {
access_log off;
log_not_found off;
expires 30d;
}
# deny access to hidden files (.whatever)
location ~ /\. {
access_log off;
log_not_found off;
deny all;
}
location ~ /dbadmin/(.*)$
{
index index.php;
alias /opt/www/phpmyadmin/$1;
}
location ~* \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /opt/www/phpmyadmin$fastcgi_script_name;
fastcgi_index index.php;
if (-f $request_filename) {
fastcgi_pass phpfpm;
}
}
location / {
# increase timeout to 2 min
proxy_read_timeout 120;
# needed to forward user IP address
proxy_set_header X-Real-IP $remote_addr;
# https support
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://127.0.0.1:8080;
}
}
phpfpm 在主 nginx.conf 中定义:
upstream phpfpm {
ip_hash;
server unix:/var/run/php-fpm/php-fpm.sock;
}