I just configured my server to multi-site revproxy using docker external network and configured my revproxy nginx container to work with fastcgi. Right now, for testing purposes, one of the sites is working, but it seems that the nginx for the website container does not correctly figure out the path for laravel index file and only provides me with the default "Welcome nginx" page.
I would be very grateful for any help.
My Dockerfile
for revproxy container
FROM nginx:alpine
EXPOSE 80/tcp
EXPOSE 443/tcp
CMD ["/bin/sh", "-c", "exec nginx -g 'daemon off;';"]
WORKDIR /var/www
docker-compose
for revproxy container
version: '3.8'
services:
nginx-proxy:
build: ./
container_name: nginx-proxy
ports:
- 80:80
- 443:443
volumes:
- ./default.conf:/etc/nginx/conf.d/default.conf
- /var/www:/var/www/html
- ./backend-not-found.html:/var/www/html/backend-not-found.html
- ./certs:/etc/nginx/certs:ro
networks:
- proxy
restart: always
networks:
proxy:
external:
name: nginx-proxy
nginx.conf
file for revproxy container
server {
listen 80;
server_name site.com;
charset UTF-8;
root /var/www/html/laravel/public;
error_page 404 /backend-not-found.html;
location = /backend-not-found.html {
allow all;
}
location ~ \.php$ {
resolver 127.0.0.11;
set $upstream laravel-app:9000;
# nginx will now start if host is not reachable
fastcgi_pass $upstream;
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
location / {
resolver 127.0.0.11;
set $upstream http://laravel-nginx:80;
# nginx will now start if host is not reachable
proxy_pass $upstream;
try_files $uri $uri/ /index.php?$query_string;
gzip_static on;
}
}
# Default
server {
listen 80 default_server;
server_name _;
root /var/www/html;
charset UTF-8;
error_page 404 /backend-not-found.html;
location = /backend-not-found.html {
allow all;
}
location / {
return 404;
}
access_log off;
log_not_found off;
error_log /var/log/nginx/error.log error;
}
And docker-compose
file for website container
version: '3.8'
services:
#PHP Service
app:
build:
args:
user: alex
uid: 1000
context: ./
dockerfile: Dockerfile
container_name: ${APP_NAME}-app
restart: always
tty: true
working_dir: /var/www
ports:
- 9000:9000
links:
- db
volumes:
- ./:/var/www
- ./docker-compose_configs/php/custom.ini:/usr/local/etc/php/conf.d/custom.ini
networks:
- proxy
- app-network
#Nginx Service
nginx:
image: nginx:alpine
container_name: ${APP_NAME}-nginx
restart: always
tty: true
ports:
- 8080:80
restart: always
volumes:
- ./:/var/www/html
networks:
- proxy
- app-network
depends_on:
- app
links:
- app
#MySQL Service
db:
image: mysql:latest
container_name: ${APP_NAME}-db
restart: unless-stopped
tty: true
ports:
- 3306:3306
environment:
MYSQL_DATABASE: ${DB_DATABASE}
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
MYSQL_PASSWORD: ${DB_PASSWORD}
MYSQL_USER: ${DB_USERNAME}
SERVICE_TAGS: dev
networks:
- app-network
volumes:
- dbdata:/var/lib/mysql
- ./docker-compose_configs/mysql/my.cnf:/etc/mysql/my.cnf
#PhpMyAdmin
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: ${APP_NAME}-pma
environment:
PMA_HOST: db
PMA_ARBITRARY: 1
UPLOAD_LIMIT: 400M
restart: always
networks:
- app-network
ports:
- 8081:80
depends_on:
- nginx
- db
#elasticsearch
elasticsearch:
image: elasticsearch:7.12.1
container_name: ${APP_NAME}-elasticsearch
volumes:
- elasticsearch-data:/usr/share/elasticsearch/data
environment:
- discovery.type=single-node
- cluster.routing.allocation.disk.threshold_enabled=false
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
ports:
- "9200:9200"
networks:
- app-network
depends_on:
- db
#Docker Networks
networks:
app-network:
name: ${APP_NAME}-network
driver: bridge
proxy:
external:
name: nginx-proxy
#Volumes
volumes:
dbdata:
driver: local
elasticsearch-data:
driver: local