So I have a basic docker setup with nginx and php-fpm that gets deployed to AWS ECS:
Dockerfile for nginx
# Install nginx
FROM --platform=linux/amd64 nginx:latest
# Use custom configs
ADD nginx/conf/nginx.conf /etc/nginx/conf.d/default.conf
Nginx config file
server {
server_name localhost;
root /usr/share/nginx/html/public;
index index.php;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass localhost:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
Dockerfile for php-fpm
# Install nginx
FROM --platform=linux/amd64 php:8.1-fpm
# Add the files
COPY dist /usr/share/nginx/html
Question
Note: This setup works well when I deploy to AWS.
But when I try the images locally, it does not work (Bad Gateway) because the nginx container does not find localhost:9000
defined in the nginx config. I have to use localhost due to the AWSVPC network mode.
How can I also make it work locally without editing too many things? Is there a config option when I run the containers locally? Right now, I run them like this:
docker run -p 8001:80 -d --name $DEPLOY_NAME_NGINX $DEPLOY_NAME_NGINX
docker run -d --name $DEPLOY_NAME_PHP_FPM $DEPLOY_NAME_PHP_FPM