I'm trying to migrate my legacy monolith to k8s, now I have nginx and php-fpm (with code) images and I want nginx to just serve http traffic and pass it to fpm, but nginx insist on having files, I don't have try_files
directive, but it tries to find root and index files anyways.
So is it at all possible to not mount source code to nginx, I really don't see why it should be there, but I couldn't find any working example
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"
Nginx is the DevOps community's most beloved http web server. And developers love the PHP programming language because it enables them to quickly build and deploy interactive websites. As such, it's no wonder that so many sys admins need to configure Nginx, PHP and PHP-FPM on both Linux and Windows servers.
Since Nginx does not contain native PHP processing like some other web servers, we will need to install php-fpm , which stands for “fastCGI process manager”. We will tell Nginx to pass PHP requests to this software for processing.
PHP-FPM (FastCGI Process Manager) is an alternative to FastCGI implementation of PHP with some additional features useful for sites with high traffic. It is the preferred method of processing PHP pages with NGINX and is faster than traditional CGI based methods such as SUPHP or mod_php for running a PHP script.
By default the web server and php-fpm runs with the user called www-data.
The problem is that the index
directive needs the file index.php
to exist, in order to internally redirect the URI /
to /index.php
.
You can avoid the index
directive by adding a location /
to internally redirect everything to /index.php
.
For example:
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With