是否可以在不安装卷的情况下将请求传递给php-fpm

我正在尝试将旧式整体迁移到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;
}

转载注明原文:是否可以在不安装卷的情况下将请求传递给php-fpm - 代码日志