【发布时间】:2020-06-01 14:59:28
【问题描述】:
我有这个基本的 conf 文件:
server {
root /usr/share/nginx/html/default/public;
location / {
try_files $uri /index.php$is_args$args;
}
location ~ ^/index\.php(/|$) {
fastcgi_pass my-php:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
internal;
fastcgi_param SERVER_PORT $server_port;
}
location ~ \.php$ {
return 404;
}
location ~ /\.ht {
deny all;
}
}
位于 Nginx docker 容器中:/etc/nginx/conf.d/default.conf
如果我请求网站,它会很好用
127.0.0.1:8080
但如果我想从浏览器访问文件,则会出现 404 失败: 127.0.0.1:8080/check.php
即使文件存在于公共目录中,如果我将其重命名为 index.php,它会通过请求 127.0.0.1:8080 加载而不会出现任何问题,但是需要在 nginx conf 中更改什么,因此 check.php 文件将由 @ 可用987654325@?
问题2:
我可以按预期请求127.0.0.1:8080 200 OK 和 BODY 但我得到:
http://127.0.0.1:8080/index.php 404 Not Found
http://127.0.0.1:8080/check.php 404 Not Found
如果我关闭这个块:
location / {
try_files $uri /index.php$is_args$args;
}
我得到 access.log "GET / HTTP/1.1" 403
和请求-响应
http://127.0.0.1:8080/ 403 Forbidden
但这种匹配似乎有效:
location ~ ^/index\.php(/|$) { ... }
对于 php,因为如果我让 fastcgi_pass 无效
fastcgi_pass wrong-containername:9000;
我得到错误而不是 200 OK。
1.如何为 php-fpm 位置制作一个可以使用的模式
http(s)://127.0.0.1:8080/
http(s)://127.0.0.1:8080/index.php
http(s)://127.0.0.1:8080/check.php
2.And 附加处理所有其他使用 php-fpm 到目录的请求,其中可能是 index.php、check.php 或whatever.php
http(s)://127.0.0.1:8080/*
【问题讨论】:
标签: php nginx server http-status-code-404 config