good morning, I am a novice user in Docker. I was going to launch Docker for a Laraveli project, and when I run this project with the help of docker-compose nginx runs on port 8000, but inside the browser when it opens Reply file docker-compose.yml
version: "3.8"
services:
server:
image: 'nginx:stable-alpine'
ports:
- '80:80'
volumes:
- ./src:/var/www/html
- ./Docker/nginx/:/etc/nginx/conf.d/
php:
build:
context: .
dockerfile: Docker/php/php.Dockerfile
volumes:
- ./src:/var/www/html:delegated
mysql:
image: mysql:5.7
env_file:
- Docker/mysql/mysql.env
file nginx.conf
server {
listen 80;
index index.php index.html;
server_name localhost;
root /var/www/html/public;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(. \.php)(/. )$;
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
Folder structure:
ِDocker
php
nginx
mysql
src
docker-compose.yml
CodePudding user response:
Can you show docker file ?
Example for docker-compose.yml
#PHP Service
php_app:
build:
context: .
dockerfile: Dockerfile
image: php:8.0
container_name: php_app
restart: unless-stopped
tty: true
volumes:
- ./:/var/www
environment:
SERVICE_NAME: app
SERVICE_TAGS: dev
working_dir: /var/www
networks:
- app-network
#Nginx Service
php_webserver:
image: nginx
container_name: php_webserver
restart: unless-stopped
tty: true
working_dir: /var/www
volumes:
- ./:/var/www
- ./docker/nginx/:/etc/nginx/conf.d/
ports:
- 8008:80
- 446:443
networks:
- app-network
CodePudding user response:
server {
listen 80;
index index.php index.html;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /var/www/public;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(. \.php)(/. )$;
fastcgi_pass php_app:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
try this nginx conf