If you would like to run your laravel application with nginx you can use the following docker settings.
Here I supposed your application at: /var/www/laravelapp
So the file coposition would be as follow:
1. Your docker-compose file: /var/www/laravelapp/docker-compose.yml
version: "3.1"
services:
webserver:
image: nginx:alpine
restart: always
container_name: laravel-webserver
working_dir: /application
volumes:
- /var/www/laravelapp:/application
- /var/www/laravelapp/docker/nginx/nginx.conf:/etc/nginx/conf.d/default.conf
ports:
- "82:80"
env_file:
- .env
networks:
- intranet
php-fpm:
build: docker/php-fpm
restart: always
container_name: laravel-fpm
working_dir: /application
volumes:
- /var/www/laravelapp:/application
env_file:
- .env
networks:
- intranet
networks:
intranet:
external: false
2. Nginx dockerfile /var/www/laravelapp/docker/Dockerfile
FROM phpdockerio/php71-fpm:latest
# Install selected extensions and other stuff
RUN apt-get update \
&& apt-get -y --no-install-recommends install php7.1-mysql php7.1-mbstring php7.1-gd git \
&& apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*
WORKDIR "/application"
3. Nginx host settings /var/www/laravelapp/docker/nginx/nginx.conf
server {
listen 80 default;
client_max_body_size 108M;
access_log /var/log/nginx/application.access.log;
root /application/public;
index index.php;
if (!-e $request_filename) {
rewrite ^.*$ /index.php last;
}
location ~ \.php$ {
fastcgi_pass php-fpm:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PHP_VALUE "error_log=/var/log/nginx/application_php_errors.log";
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
include fastcgi_params;
}
}
Let me know if still you getting any issue.