Description
I'm using this image to run multiple sites/app on a single nginx instance. So far, I was able to run a static site and a nodejs application without problems but I'm facing an issue with a php application created with codeigniter.
Essentially the project structure looks like this:
nginx
nginx-proxy
docker-compose.yml
php-application
docker-compose.yml
Inside the php-application/docker-compose.yml
I have this:
version: '3.7'
services:
php-fpm:
container_name: boilerplate_app
restart: always
build:
context: .
dockerfile: ./docker/php-fpm/Dockerfile
volumes:
- ./src:/var/www/html
environment:
# NGINX-PROXY ENVIRONMENT VARIABLES: UPDATE ME
- VIRTUAL_HOST=mysite.com
- VIRTUAL_ROOT=/var/www/html
- VIRTUAL_PORT=9000
- VIRTUAL_PROTO=fastcgi
- LETSENCRYPT_HOST=mysite.com
- LETSENCRYPT_EMAIL=info@mysite.it
# /END NGINX-PROXY ENVIRONMENT VARIABLES
ports:
- '9000:80'
expose:
- 9000
networks:
- proxy
#nginx:
# container_name: boilerplate_nginx
# build: ./docker/nginx
# restart: always
# volumes:
# - ./src:/var/www/html
# - ./docker/nginx/nginx.conf:/etc/nginx/nginx.conf
# - ./docker/nginx/sites/:/etc/nginx/sites-available
# - ./docker/nginx/conf.d/:/etc/nginx/conf.d
# ports:
# - '8880:80'
# depends_on:
# - php-fpm
# networks:
# - proxy
database:
container_name: boilerplate_db
restart: always
build:
context: ./docker/database
environment:
- MYSQL_DATABASE=boilerplate
- MYSQL_USER=user
- MYSQL_PASSWORD=secret
- MYSQL_ROOT_PASSWORD=secret
volumes:
- ./docker/database/data.sql:/docker-entrypoint-initdb.d/data.sql
phpmyadmin:
container_name: boilerplate_phpmyadmin
image: phpmyadmin/phpmyadmin
restart: always
ports:
- 8088:80
environment:
- PMA_HOST=database
- MYSQL_USER=user
- MYSQL_PASSWORD=secret
- MYSQL_ROOT_PASSWORD=secret
depends_on:
- database
networks:
proxy:
external:
name: nginx-proxy
The php application runs over php-fpm
specifically on the port 9000
using fastcgi
, for this I used the following directives:
- VIRTUAL_ROOT=/var/www/html/public
- VIRTUAL_PORT=9000
- VIRTUAL_PROTO=fastcgi
to make it working, I also specified the VIRTUAL_ROOT
that should redirect all the request on the index.php which is available in this directory /var/www/html/public
. Project structure:
php-application
src
node_modules
app
public
tests
vendor
writable
.env
composer.json
package.json
spark
the problem's that when I start the php-application
container using docker-compose up --build -d
, I get this when I visit mysite.com
(hide for privacy the real domain):
File not found.
Inspecting the nginx
log using sudo docker logs -f nginx
I get:
[error] 30#30: *39 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 2.38.140.109, server: mysite.com, request: "GET / HTTP/2.0", upstream: "fastcgi://172.28.0.7:9000", host: "mysite.com"
mysite.com 2.38.140.109 - - [29/Mar/2021:17:52:31 +0000] "GET / HTTP/2.0" 404 16 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36 Edg/89.0.774.63"
what I did wrong?
UPDATE:
output of /var/log/nginx/error.lg
2021/03/30 10:53:22 [notice] 98#98: signal process started
2021/03/30 10:53:32 [warn] 99#99: no resolver defined to resolve r3.o.lencr.org while requesting certificate status, responder: r3.o.lencr.org, certificate: "/etc/nginx/certs/example.com.crt"
2021/03/30 10:53:32 [error] 99#99: *305 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 212.171.224.237, server: example.com, request: "GET / HTTP/2.0", upstream: "fastcgi://172.28.0.7:9000", host: "example.com"
2021/03/30 10:53:32 [error] 99#99: *305 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 212.171.224.237, server: example.com, request: "GET /favicon.ico HTTP/2.0", upstream: "fastcgi://172.28.0.7:9000", host: "example.com", referrer: "https://example.com/"
UPDATE 2
/etc/resolve.conf