【发布时间】:2021-11-10 09:47:33
【问题描述】:
在以下站点配置文件中,我正在尝试:
-
在第一次访问时加载 index.php。
-
加载出现在 /uploads/ 目录中的文件。
-
任何其他请求仍应由 index.php 处理。
server { listen 80 default_server; listen [::]:80 default_server; root /home/va/www/example; # Add index.php to the list if you are using PHP # index index.php; server_name example.dev; location ~ .* { try_files /dev/null @php; } location /uploads/ { try_files $uri =404; expires 30d; } location @php { include snippets/fastcgi-php.conf; #pretty url fastcgi_param SCRIPT_FILENAME $document_root/index.php; fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; } }
但是,最后一部分中断了。换句话说:
/ works
/?test=test works
/uploads/test.jpeg works
/random_string does not work and returns 404 error
我的理解是location ~ .*别无选择,只能匹配一切。 404错误来自哪里?
【问题讨论】:
标签: nginx-location