Symfony 2.6 on Docker nginx giving 404 - docker

Currently working on a legacy app built with Symfony 2.6 (Originally, the app is running on Centos7 on both dev and prod, but due to time constraint, I just need to make it work on local so I can continue working with feature requests).
I am adding Docker to the project as I am having problem managing dependencies on my local machine.
Setup:
ubuntu 18.04
nginx
docker 19.03
My current problem is:
- I am getting 404 on all routes I am hitting.
- I can see there are logs from the docker logs <container> -f (Update: This is the apache logs)
Logs:
192.168.176.1 - - [01/Oct/2019:14:56:17 +0000] "GET /user HTTP/1.1" 404 209 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36"
192.168.176.1 - - [01/Oct/2019:14:57:51 +0000] "GET /user HTTP/1.1" 404 209 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36"
192.168.176.1 - - [02/Oct/2019:05:31:59 +0000] "GET /user HTTP/1.1" 404 209 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36"
//truncated
This is the folder structure:
|app
|bin
|docker
|app
default
Dockerfile
php-fpm.conf
start-container.sh
supervisord.conf
|src
|vendor
|web
app.php
app_dev.php
.htaccess
//some other stuff
.env
.gitignore
composer.json
composer.lock
docker-compose.yml
This is the ./web/.htaccess
DirectoryIndex app.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
RewriteRule .? %{ENV:BASE}/app.php [L]
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
RedirectMatch 302 ^/$ /app.php/
</IfModule>
</IfModule>
This is the ./docker/app/default
server {
listen 80 default_server;
root /var/www/html/public;
index index.html index.htm index.php;
server_name _;
charset utf-8;
location = /favicon.ico { log_not_found off; access_log off; }
location = /robots.txt { log_not_found off; access_log off; }
location / {
try_files $uri $uri/ /app.php$is_args$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.1-fpm.sock;
}
error_page 404 /app.php;
}
This is the ./docker/app/Dockerfile
FROM ubuntu:18.04
LABEL maintainer="My name"
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update \
&& apt-get install -y gnupg tzdata \
&& echo "Asia/Dubai" > /etc/timezone \
&& dpkg-reconfigure -f noninteractive tzdata \
&& apt-get install -y software-properties-common \
&& add-apt-repository -y ppa:ondrej/php
RUN apt-get update \
&& apt-get install -y curl zip unzip git supervisor sqlite3 make \
nginx php7.1-fpm php7.1-cli \
php7.1-pgsql php7.1-sqlite3 php7.1-gd \
php7.1-curl php7.1-memcached \
php7.1-imap php7.1-mysql php7.1-mbstring \
php7.1-xml php7.1-zip php7.1-bcmath php7.1-soap \
php7.1-intl php7.1-readline php7.1-xdebug \
php-msgpack php-igbinary \
&& php -r "readfile('http://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer \
&& mkdir /run/php \
&& apt-get -y autoremove \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/\* /tmp/\* /var/tmp/\* \ //had to escape the * as it was commenting out the code in stackoverflow editor
&& echo "daemon off;" >> /etc/nginx/nginx.conf
RUN ln -sf /dev/stdout /var/log/nginx/access.log \
&& ln -sf /dev/stderr /var/log/nginx/error.log
ADD default /etc/nginx/sites-available/default
ADD supervisord.conf /etc/supervisor/conf.d/supervisord.conf
ADD php-fpm.conf /etc/php/7.1/fpm/php-fpm.conf
ADD start-container.sh /usr/bin/start-container
RUN chmod +x /usr/bin/start-container
ENTRYPOINT ["start-container"]
This is the ./docker-compose.yml
version: '3'
services:
app:
build: ./docker/app
image: 'be/app:latest'
networks:
- appnet
volumes:
- './:/var/www/html:cached'
ports:
- '${APP_PORT}:80'
working_dir: /var/www/html
cache:
image: 'redis:alpine'
networks:
- appnet
volumes:
- 'cachedata:/data'
db:
image: 'mysql:5.7'
environment:
MYSQL_ROOT_PASSWORD: '${DB_ROOT_PASSWORD}'
MYSQL_DATABASE: '${DB_DATABASE}'
MYSQL_USER: '${DB_USER}'
MYSQL_PASSWORD: '${DB_PASSWORD}'
ports:
- '${DB_PORT}:3306'
networks:
- appnet
volumes:
- 'dbdata:/var/lib/mysql'
networks:
appnet:
driver: bridge
volumes:
dbdata:
driver: local
cachedata:
driver: local
Additional note:
I added Docker to another legacy project using Symfony 2.8, and it is working.
Using the same setup as mentioned in this question.
Any help is very much appreciated.
Thank you.

I'm not too familiar with nginx configs but in my opinion root /var/www/html/public looks odd for old symfony, should have web instead of public

Related

I need to host my react app on my domain and my api on my subdomain with Nginx on the Ubuntu server and Nginx on Docker

So basically, I have two Nginx processes. One runs on an ubuntu server itself (20.04 LTS) (for the frontend), and the other runs on docker on the ubuntu server (for the backend).
I have created a server block for both the front end and the backend but if I browse the backend on the subdomain (api.domain.com) it displays a 404 not found page with the current configuration.
The one running on the ubuntu server serves the react app with the server block below:
server {
listen 80;
# listen [::]:80;
server_name domain.com www.domain.com;
location / {
proxy_pass http://localhost:3000;
}
}
This server block for the react app works as intended, however, the other app which is my API built with Laravel, MySQL, and Nginx to serve the app with docker is not working as it should.
This is the server block for the API
server {
listen 80;
server_name api.domain.com www.api.domain.com;
root /var/www/public;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ .php$ {
try_files $uri /index.php =404;
fastcgi_pass 172.22.0.2:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
docker-compose file
version: '3'
services:
#PHP Service
app:
build:
context: .
dockerfile: Dockerfile
image: {docker_image:latest}
container_name: app
restart: unless-stopped
tty: true
environment:
SERVICE_NAME: app
SERVICE_TAGS: dev
working_dir: /var/www
volumes:
- ./:/var/www
- ./php/local.ini:/usr/local/etc/php/conf.d/local.ini
networks:
- app-network
#Nginx Service
webserver:
image: nginx:alpine
container_name: webserver
restart: unless-stopped
tty: true
ports:
- "8000:80"
- "445:443"
depends_on:
- app
volumes:
- ./:/var/www
# - ./nginx/conf.d/app.conf:/etc/nginx/sites-available/{api.domain.com}
networks:
- app-network
#MySQL Service
db:
image: mysql:8.0
container_name: ${APP_NAME}_db
restart: unless-stopped
tty: true
ports:
- "3307:3306"
environment:
MYSQL_DATABASE: ${DB_DATABASE}
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
SERVICE_TAGS: dev
SERVICE_NAME: mysql
volumes:
- dbdata:/var/lib/mysql
- ./mysql/my.cnf:/etc/mysql/my.cnf
networks:
- app-network
#Docker Networks
networks:
app-network:
driver: bridge
#Volumes
volumes:
dbdata:
driver: local
Dockerfile:
FROM php:8.0-fpm
# Copy composer.lock and composer.json
COPY composer.lock composer.json /var/www/
# Set working directory
WORKDIR /var/www
# Install dependencies
RUN apt-get update && apt-get install -y \
build-essential \
libpng-dev \
libwebp-dev \
libjpeg62-turbo-dev \
libfreetype6-dev \
locales \
zip \
jpegoptim optipng pngquant gifsicle \
vim \
unzip \
git \
curl \
libzip-dev
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install extensions
RUN docker-php-ext-install pdo_mysql zip exif pcntl
RUN docker-php-ext-configure gd --enable-gd --with-jpeg --with-webp --with-freetype
RUN docker-php-ext-install gd
# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Add user for laravel application
# RUN groupadd -g 1000 www
# RUN useradd -u 1000 -ms /bin/bash -g www www
# Copy existing application directory contents
COPY . /var/www
# Copy existing application directory permissions
COPY --chown=www-data:www-data . /var/www
# RUN chown -R www:www /var/www
# RUN chmod -R 755 /var/www
# Change current user to www
USER www-data
# Expose port 9000 and start php-fpm server
EXPOSE 9000
CMD ["php-fpm"]
Already created a symbolic link for the sites-enabled directory.
I have solved this exact problem before but I didn't document it, it has become really frustrating finding a solution this past few days.
I would really appreciate if anyone has a solution to this problem.

Docker or symfony missconfig. error SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: No such host is known

How can I fix this?
Is this a miss config in docker-compose or maybe is a miss config in PHP-fpm or I should do something in simfony env.
I really don't know what to change. If I call doctrine from console require localhost as host and when the browser use pdo need to have host as MySQL (the docker name)
Very strange issue. After hours of debugging I find out why doctrine:migrations:migrate failed
C:\Users\Admin\Development\lemp\www\web>php bin/console doctrine:migrations:migrate
returning the following error:
An exception occurred in driver: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: No such host is known.
I found out that runing migration is working if I replace the host in the .env file:
DATABASE_URL=mysql://dummy:dummy#mysql:3306/dummy?serverVersion=5.7
with
DATABASE_URL=mysql://dummy:dummy#localhost:3306/dummy?serverVersion=5.7
But a new problem arose. The http://localhost:8080/ require the old env with mysql to run:
DATABASE_URL=mysql://dummy:dummy#mysql:3306/dummy?serverVersion=5.7
You can find all the config file in my public repo:
https://github.com/dumitriucristian/nginx-server
This is my docker-compose.yml content
version: '3'
# https://linoxide.com/containers/setup-lemp-stack-docker/
# http://www.inanzzz.com/index.php/post/zpbw/creating-a-simple-php-fpm-nginx-and-mysql-application-with-docker-compose
#https://www.pascallandau.com/blog/php-php-fpm-and-nginx-on-docker-in-windows-10/
#http://www.inanzzz.com/index.php/post/0e95/copying-symfony-application-into-docker-container-with-multi-stage-builds
#https://learn2torials.com/a/dockerize-reactjs-app
#https://knplabs.com/en/blog/how-to-dockerise-a-symfony-4-project
services:
nginx:
build:
context: .
dockerfile: docker/nginx/Dockerfile
ports:
- "8080:80"
volumes:
- ./nginx-server/logs:/var/log/nginx
- ./nginx-server/default.conf:/etc/nginx/conf.d/default.conf
- ./www/:/srv/www
depends_on:
- phpfpm
phpfpm:
build:
context: .
dockerfile: docker/phpfpm/Dockerfile
ports:
- "9000:9000"
volumes:
- ./www:/srv/www
- ./docker/phpfpm/default.conf:/usr/local/etc/php-fpm.d/default.conf
environment:
MYSQL_USER: "dummy"
MYSQL_PASSWORD: "dummy"
mysql:
image: mysql:5.7
ports:
- 3306:3306
depends_on:
- phpfpm
environment:
MYSQL_ROOT_PASSWORD: "dummy"
MYSQL_DATABASE: "dummy"
MYSQL_USER: "dummy"
MYSQL_PASSWORD: "dummy"
app:
build:
context: .
dockerfile: docker/app/Dockerfile
environment:
- NODE_ENV=test
command: npm run start
ports:
- 3000:3000
volumes:
- ./app:/app
nginx\Dockerfile
FROM nginx:latest
RUN apt-get update && apt-get install -y unzip zlib1g-dev git curl libmcrypt-dev bcrypt nano man
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer
WORKDIR /usr/src
RUN mkdir -p web
COPY ./www/web /usr/src/web
RUN PATH=$PATH:/web/vendor/bin:bin
EXPOSE 9000
EXPOSE 80
phpfpm\Dockerfile
FROM php:7.4.0-fpm-alpine
RUN apk update \
&& apk add --no-cache $PHPIZE_DEPS \
git \
zip \
unzip \
&& docker-php-ext-install \
opcache \
pdo_mysql \
&& docker-php-ext-enable \
opcache \
&& rm -rf \
/var/cache/apk/* \
/var/lib/apt/lists/*
COPY ./docker/phpfpm/php.ini /usr/local/etc/php/conf.d/php.override.ini
COPY ./nginx-server/default.conf /usr/local/etc/php-fpm.d/default.conf``
and nginx default.conf
server {
listen 0.0.0.0:80;
listen [::]:80 default_server;
server_name _;
root /srv/www/web/public;
index index.htm index.html index.php ;
default_type text/html;
location ~* \.php$ {
try_files $uri $uri/ /index.php;
fastcgi_pass phpfpm:9000;
#fastcgi_pass unix:/run/php/php7.4-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#fastcgi_pass unix:/tmp/phpcgi.socket;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_index index.php;
include fastcgi_params;
}
}
Thanks,
I am new to dev-ops but I try.

how can I access my web app in url after docker composer up -d

Hi can you help me why I cannot see my page when I access in browser app.dev , it says unable to connect.I only see the echo in the console can you help me please in my docker-compose.yml and in my dockerfile what is missing. is my php is correct image ?
version: "3.7"
services:
web:
build: .
image: nginx:latest
container_name: nginx-container
ports:
- "8080:80"
expose:
- 9000
volumes:
- ./:/var/www/myapp
- ./default.conf:/etc/nginx/conf.d/default.conf
links:
- php
php:
image: php:7-fpm
container_name: php-container
db:
image: mysql
container_name: mysql-container
command: --default-authentication-plugin=mysql_native_password
volumes:
- ./mysql-data:/var/lib/mysql
expose:
- 3306
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: rootpass
site.conf
server {
listen 80;
index index.php;
server_name app.dev;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /var/www/myapp;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index index.php;
fastcgi_pass php:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
dockerfile
FROM php:7.2-cli
COPY . /var/www/myapp
WORKDIR /var/www/myapp
RUN apt-get update && apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
&& docker-php-ext-install -j$(nproc) iconv \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install -j$(nproc) gd
entrypoint [ "php", "./index.php" ]
As I checked your docker-compose.yaml file:
You have mounted you current path to /var/www which suppose to have projects files.
But sit.conf:
Configure the root document for Nginx to be / directory.
So what happens here is Nginx try to find index.php in / and when it can't find it uses the default configuration for Nginx and shows its default page.
To solve your issue:
Modify site.conf root to be root /var/www/ and of course check the permissions and make sure it's right and it will work.

Docker / Nginx / Symfony4: php modifications aren't displayed

I'm setting up a docker stack for a Symfony 4 application with Nginx and PHP 7. I need advice for my docker stack because i met one problem : every changes in a PHP file (a controller, a repository, an entity etc...) aren't displayed. Each time, i need to down ma docker stack and restart to see the changes, even for a simple dump().
I verified OPCache is enabled and configured like in Symfony documentation.
I think the problem is in my docker stack.
This is docker-compose.yml :
version: '2.2'
services:
# PHP
php:
build:
context: docker/php7-fpm
args:
TIMEZONE: ${TIMEZONE}
container_name: dso_php
volumes:
- ".:/var/www/myproject:rw,cached"
- "./docker/php7-fpm/www.conf:/usr/local/etc/php-fpm.d/www.conf"
- "./docker/php7-fpm/php.ini:/usr/local/etc/php/conf.d/030-custom.ini"
env_file:
- .env
working_dir: /var/www/myproject
# NGINX
nginx:
build:
context: docker/nginx
args:
NGINX_HOST: ${NGINX_HOST}
container_name: dso_nginx
ports:
- 80:80
depends_on:
- php
volumes:
- ".:/var/www/myproject:cached"
- ./logs/nginx/:/var/log/nginx
env_file:
- .env
environment:
- NGINX_HOST=${NGINX_HOST}
I build my own Dockerfile for PHP and Nginx:
First PHP, here the Dockerfile :
FROM php:7.2-fpm
MAINTAINER HamHamFonFon <balistik.fonfon#gmail.com>
USER root
# Utils
RUN apt-get update \
&& apt-get upgrade -y \
&& apt-get install -y curl less vim libpq-dev wget gnupg libicu-dev libpng-dev zlib1g-dev sudo wget \
&& docker-php-ext-install mysqli \
&& docker-php-ext-install pdo_mysql \
&& docker-php-ext-install intl \
&& docker-php-ext-install opcache \
&& docker-php-ext-install zip \
&& docker-php-ext-install gd
RUN apt-get install -y zip unzip
# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer \
&& composer --version
# npm & node
RUN curl -sL https://deb.nodesource.com/setup_9.x | bash
RUN apt-get install -y nodejs npm \
&& update-alternatives --install /usr/bin/node node /usr/bin/nodejs 10
# build tools
RUN apt-get install -y build-essential
# yarn package manager
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
&& echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
# Git
RUN apt-get install -y git
# bugfix: remove cmdtest to install yarn correctly.
RUN apt-get remove -y cmdtest
RUN apt-get update
RUN apt-get install -y yarn
# Clear archives in apt cache folder
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint
RUN chmod +x /usr/local/bin/docker-entrypoint
ENTRYPOINT ["docker-entrypoint"]
php.ini :
; General settings
date.timezone = Europe/Paris
xdebug.max_nesting_level=500
short_open_tag = Off
memory_limit="512M"
; Error reporting optimized for production (http://www.phptherightway.com/#error_reporting)
display_errors = Off
display_startup_errors = Off
error_reporting = E_ALL
log_errors = On
error_log = /var/log/php-app/error.log
apc.enable_cli = 1
# http://symfony.com/doc/current/performance.html
opcache.interned_strings_buffer = 16
opcache.memory_consumption = 256
opcache.max_accelerated_files = 20000
opcache.validate_timestamps=0
; maximum memory allocated to store the results
realpath_cache_size=4096K
; save the results for 10 minutes (600 seconds)
realpath_cache_ttl=600
And www.conf (i have removed in this exemple all commented lines) :
[www]
user = site
listen = [::]:9000
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
php_admin_value[upload_max_filesize] = 50M
php_admin_value[post_max_size] = 50M
Now, for nginx :
First, Dockerfile :
FROM debian:jessie
ARG NGINX_HOST
MAINTAINER HamHamFonFon <balistik.fonfon#gmail.com>
# Install nginx
RUN apt-get update && apt-get install -y nginx
# Configure Nginx
ADD nginx.conf /etc/nginx/
ADD symfony.conf /etc/nginx/conf.d/
RUN sed "/server_name nginx_host;/c\ server_name ${NGINX_HOST};" -i /etc/nginx/conf.d/symfony.conf
RUN echo "upstream php-upstream { server php:9000; }" > /etc/nginx/conf.d/upstream.conf
RUN usermod -u 1000 www-data
# Run Nginx
CMD ["nginx"]
# Expose ports
EXPOSE 80
nginx.conf :
user www-data;
worker_processes 4;
pid /run/nginx.pid;
events {
worker_connections 2048;
multi_accept on;
use epoll;
}
http {
server_tokens off;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 15;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log off;
error_log off;
gzip on;
gzip_disable "msie6";
include /etc/nginx/conf.d/*.conf;
open_file_cache max=100;
client_body_temp_path /tmp 1 2;
client_body_buffer_size 256k;
client_body_in_file_only off;
}
daemon off;
And finally, symfony.conf :
server {
listen 80;
listen [::]:80;
server_name nginx_host;
client_max_body_size 20M;
root /var/www/deep-space-objects/public;
location / {
try_files $uri /index.php$is_args$args;
}
location ~ ^/(index)\.php(/|$) {
fastcgi_pass php-upstream;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
internal;
}
location ~ \.php$ {
return 404;
}
error_log /var/log/nginx/symfony_error.log;
access_log /var/log/nginx/symfony_access.log;
}
In Dockerfile, the command "sed" replace "nginx_host" by the server name i declare in .env file.
My problem looks like this one : Docker with Symfony 4 - Unable to see the file changes but i have verified the OPCache configuration.
How can i check if nginx and php communicate ? Are there some badthings in my stack i can improve ?
Thank you, i don't know how to looking for.

Nginx docker communication to php container - connection refused

New to docker and nginx set up at this level. Having issues getting nginx to talk to php container. Keep getting 502 Bad Gatewaywhen navigating, with the following errors from docker:
web | 2018/03/21 09:25:40 [error] 6#6: *6 connect() failed (111: Connection refused) while connecting to upstream, client: 172.18.0.1, server: web, request: "GET / HTTP/1.1", upstream: "fastcgi://172.18.0.4:9000", host: "localhost:8080"
web | 172.18.0.1 - - [21/Mar/2018:09:25:40 +0000] "GET / HTTP/1.1" 502 575 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.162 Safari/537.36" "-"
web | 2018/03/21 09:25:40 [error] 6#6: *6 connect() failed (111: Connection refused) while connecting to upstream, client: 172.18.0.1, server: web, request: "GET /favicon.ico HTTP/1.1", upstream: "fastcgi://172.18.0.4:9000", host: "localhost:8080", referrer: "http://localhost:8080/"
web | 172.18.0.1 - - [21/Mar/2018:09:25:40 +0000] "GET /favicon.ico HTTP/1.1" 502 575 "http://localhost:8080/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.162 Safari/537.36" "-"
My nginx conf:
server {
listen 80;
# listen 443 ssl;
server_name web;
charset utf-8;
client_max_body_size 10M;
root /usr/share/nginx/html/public;
index index.php index.html index.htm;
location / {
# try to serve file directly, fallback to rewrite
# see laravel docs On Nginx, the following directive in your site configuration will allow "pretty" URLs:
try_files $uri $uri/ /index.php?$query_string;
}
location ~ ^/.+\.php(/|$) {
include fastcgi_params;
fastcgi_pass php:9000;
fastcgi_param DB_HOST mariadb:33061;
fastcgi_param DB_DATABASE homestead;
fastcgi_param DEFAULT_HOME_URL $http_host;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_buffers 4 16k;
fastcgi_buffer_size 32k;
fastcgi_busy_buffers_size 32k;
}
}
and my docker compose yaml:
version: '3'
services:
web:
container_name: web
build:
context: ./nginx
restart: always
volumes:
- "./nginx/insight.conf:/etc/nginx/conf.d/default.conf"
- "/Users/lokisinclair/Projects/nps:/usr/share/nginx/html"
ports:
- "8080:80"
links:
- php
- mariadb
mailcatcher:
container_name: mailcatcher
image: yappabe/mailcatcher
ports:
- 1025:1025
- 1080:1080
php:
container_name: php
build:
context: ./php
restart: always
volumes:
- "/Users/lokisinclair/Projects/nps:/usr/share/nginx/html"
ports:
- "9000:9000" # PHP
- "5000:5000" # ProcessTags.py
links:
- mariadb
- mailcatcher
environment:
- DB_HOST=mariadb
- DB_USER=homestead
- DB_PASS=secret
mariadb:
container_name: db
image: mariadb
ports:
- "33061:3306"
restart: always
volumes:
- "./database:/var/lib/mysql"
- "./mariadb:/tmp"
command: mysqld --init-file="/tmp/init.sql"
environment:
- MYSQL_DATABASE=homestead
- MYSQL_USER=homestead
- MYSQL_PASSWORD=secret
I've attempted to rewrite the nginx .conf several times, using various guides but it will always respond with [XYZ] is not allowed here in...- which isn't overly helpful. This conf works, but just can't access the php container. Can anyone shed some light, please?
Update
I've since installed telnet on the web container and attempted to access port 9000, but its refused at command line too.
php dockerfile
FROM php:7.0.0-fpm
LABEL maintainer="<REMOVED>"
RUN apt-get update && apt-get upgrade -y \
g++ \
libc-client-dev \
libfreetype6-dev \
libicu-dev \
libjpeg62-turbo-dev \
libkrb5-dev \
libpq-dev \
libmagickwand-dev \
libmcrypt-dev \
libpng-dev \
libmemcached-dev \
libssl-dev \
libssl-doc \
libsasl2-dev \
zlib1g-dev \
python3.4 \
python-pip \
libmysqlclient-dev \
python-dev \
procps \
&& docker-php-ext-install \
bz2 \
iconv \
mbstring \
mysqli \
pgsql \
pdo_mysql \
pdo_pgsql \
soap \
zip \
&& docker-php-ext-configure gd \
--with-freetype-dir=/usr/include/ \
--with-jpeg-dir=/usr/include/ \
--with-png-dir=/usr/include/ \
&& docker-php-ext-install gd \
&& docker-php-ext-configure intl \
&& docker-php-ext-install intl \
&& docker-php-ext-install sockets \
&& yes '' | pecl install imagick && docker-php-ext-enable imagick \
&& docker-php-ext-configure imap --with-kerberos --with-imap-ssl \
&& docker-php-ext-install imap \
&& pecl install memcached && docker-php-ext-enable memcached \
&& pecl install mongodb && docker-php-ext-enable mongodb \
&& pecl install redis && docker-php-ext-enable redis \
&& pecl install xdebug && docker-php-ext-enable xdebug \
&& apt-get autoremove -y --purge \
&& apt-get clean \
&& rm -Rf /tmp/* \
&& pip install nltk \
&& pip install MySQL-python
# Grab python NLTK libs
RUN python -m nltk.downloader -d /usr/local/share/nltk_data all
# Set working directory to root of Insight
WORKDIR "/usr/share/nginx/html"
ADD init.sh /tmp/init.sh
CMD chmod +x /tmp/init.sh
CMD /bin/bash /tmp/init.sh
# Expose network ports
EXPOSE 5000
EXPOSE 9000

Resources