I have a question regarding the most optimal way to set up NGINX and PHP-FPM for my application with docker. So in my set up, my application code and PHP-FPM live in one docker container (the web container), and Ngnix on a separate docker container.
The trick here is that Nginx does not have access to the application files, because they are in the web container, which resulted in some configuration issues with Nginx. One of those issues is that I can't use the 'root' directive in the Nginx config file, I had to use 'alias' instead. But I managed to get Nginx to point to the proper 'index.php' file in the end (see the config file at the end).
But I was wondering what is the most optimal way to define the relationship between this services?
- Should I just give access to the application code to Nginx?
- Should I set up one more Nginx service in the web container, so that it will accept the requests that come from the Nginx container?
- Or maybe there is some other option that would be even better for my case?
This is my current nginx confg file (I've remove some irrelevant parts):
upstream phpserver {
server web:9000;
}
server {
listen 443 ssl http2;
server_name app;
gzip off;
location ~ ^/index\.php(/|$) {
alias /web/index.php;
fastcgi_pass phpserver;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
#include fastcgi_params;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
internal;
http2_push_preload on;
}