internal
我在通过 X-accl-Redirect 加载的站点中执行 php 脚本时遇到问题。我的/etc/nginx/sites-enabled/devdb.easy-ads.com
文件包含:
server {
root /srv/http/devdb.easy-ads.com/www;
index index.html index.htm index.nginx-debian.html index.php;
server_name devdb.easy-ads.com;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
# pass PHP scripts to FastCGI server
#
location ~ \.php$ {
include snippets/fastcgi-php.conf;
#
# # With php-fpm (or other unix sockets):
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
}
error_page 404 = /index.php;
location /phpmyadmin_internal {
internal;
alias /srv/http/phpmyadmin;
}
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/devdb.easy-ads.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/devdb.easy-ads.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
}
并且/srv/http/devdb.easy-ads.com/www/index.php
我有:
<?php
header("X-Accel-Redirect: /phpmyadmin_internal/test2.txt");
一切运行良好,文件/srv/http/phpmyadmin/test2.txt
按预期加载。但是当我将其更改为
<?php
header("X-Accel-Redirect: /phpmyadmin_internal/test.php");
它只是出现 404 错误,而不是执行/srv/http/phpmyadmin/test.php
。。这是怎么回事?我怎样才能让它在internal
网站上执行 php 脚本?
(我认为正在发生的事情是,它要求 php-fpm 加载文字 url /phpmyadmin_internal/test.php
,在将其发送到 php-fpm 之前没有正确地为其提供一个新的 uri/root-dir,但我实际上并不知道。)
答案1
首先删除alias
的指令/phpmyadmin_internal
,只需执行以下操作:
location /phpmyadmin_internal {
internal;
}
然后创建一个到目标文件夹的符号链接,例如
ln -s '/srv/http/phpmyadmin/' '/srv/http/devdb.easy-ads.com/www/phpmyadmin_internal'
瞧,一切正常(-: