我正在尝试将旧式整体迁移到k8s,现在我拥有Nginx和PHP-fpm(带有代码)图像,并且我希望Nginx仅提供http流量并将其传递给fpm,但是Nginx坚持拥有文件,我不这样做.没有try_files指令,但是无论如何它都会尝试查找根文件和索引文件.
因此,是否有可能根本不将源代码装载到Nginx上,我真的不明白为什么应该将其放在那里,但是我找不到任何有效的示例
Nginx.conf:
server {
listen 80;
index index.PHP;
# This dir exist only in PHP-fpm container
root /var/www/html/public;
location ~* \.PHP${
client_max_body_size 0;
include fastcgi_params;
fastcgi_pass PHP-fpm:9000;
fastcgi_split_path_info ^(.+\.PHP)(/.*)$;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
}
}
2018/08/17 16:44:40 [error] 9#9: *46 “/var/www/html/public/index.PHP” is not found (2: No such file or directory),client: 192.xxx.xxx.xxx,server:,request: “GET / HTTP/1.1”,host: “localhost”
192.xxx.xxx.xxx – – [17/Aug/2018:16:44:40 +0000] “GET / HTTP/1.1” 404 571 “-” “Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML,like Gecko) Chrome/65.0.3325.146 Safari/537.36” “195.xxx.xxx.xxx”
最佳答案
问题是index指令需要文件index.PHP存在,以便内部将URI /重定向到/index.PHP.
您可以通过添加位置/在内部将所有内容重定向到/index.PHP来避免使用index指令.
例如:
location / {
rewrite ^ /index.PHP last;
}
location ~* \.PHP${
root /var/www/html/public;
client_max_body_size 0;
include fastcgi_params;
fastcgi_pass PHP-fpm:9000;
fastcgi_split_path_info ^(.+\.PHP)(/.*)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $document_root;
}