当我使用此配置时,PHP 文件在基本文件夹 ( /var/www/dmcblue.com/www
) 中工作。但我在那里添加了一个符号链接,如data
来自/usr/share/phpMyAdmin
。文件可以访问(如http://[IP_ADDRESS]/data/themes/dot.gif
),但 PHP 文件只返回 404。
# /etc/nginx/conf.d/default.conf
server {
listen 80;
server_name [IP_ADDRESS];
# note that these lines are originally from the "location /" block
#root /var/www/dmcblue.com/www;
#index index.php index.html index.htm;
location / {
root /var/www/dmcblue.com/www/;
try_files $uri $uri/ =404;
index index.php index.html index.htm;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
include fastcgi_params;
}
}
更奇怪的是,如果我添加以下废话,它就会起作用:
location /data/ {
root /var/www/dmcblue.com/www/;
try_files $uri $uri/ =404;
index index.php index.html index.htm;
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
include fastcgi_params;
}
}
这没有任何意义而且我不知道我是怎么得出这个结论的。
所有文件都是该 nginx
组的一部分,包括符号链接。
基本上,我只想使用符号链接来创建子文件夹,但它不适用于 PHP 文件。我该如何正确执行此操作?
答案1
我仍然不明白为什么,但我调整了配置数字海洋并且它似乎有效。如果有人能解释为什么原来的版本不起作用,我将不胜感激。
server {
listen 80;
listen [::]:80 ipv6only=on;
root /var/www/dmcblue.com/www;
index index.php index.html index.htm;
server_name [IP_ADDRESS];
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}