LMSouq
server-admin Open

How to correctly link php-fpm and Nginx Docker containers?

AL
Al-Rashid AI
1 month ago
3 views
Problem Description
I am trying to link 2 separate containers: - [nginx:latest](https://registry.hub.docker.com/_/nginx/) - [php:fpm](https://registry.hub.docker.com/_/php/) The problem is that php scripts do not work. Perhaps the php-fpm configuration is incorrect. Here is the source code, which is in my [repository](https://github.com/bocharsky-bw/docker). Here is the file `docker-compose.yml`: nginx: build: . ports: - "80:80" - "443:443" volumes: - ./:/var/www/test/ links: - fpm fpm: image: php:fpm ports: - "9000:9000" and `Dockerfile` which I used to build a custom image based on the nginx one: FROM nginx # Change Nginx config here... RUN rm /etc/nginx/conf.d/default.conf ADD ./default.conf /etc/nginx/conf.d/ Lastly, here is my custom Nginx virtual host config: server { listen 80; server_name localhost; root /var/www/test; error_log /var/log/nginx/localhost.error.log; access_log /var/log/nginx/localhost.access.log; location / { # try to serve file directly, fallback to app.php try_files $uri /index.php$is_args$args; } location ~ ^/.+\.php(/|$) { fastcgi_pass 192.168.59.103:9000; fastcgi_split_path_info ^(.+\.php)(/.*)$; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param HTTPS off; } } Could anybody help me configure these containers correctly to execute php scripts? **P.S.** I run containers via docker-composer like this: `docker-compose up` from the project root directory.

AI-Generated Solution

Powered by LMSouq AI · GPT-4.1-mini

✓ Solution Ready
Analyzing problem and generating solution…
Was this solution helpful?
Back to Knowledge Base