Source

Setup Docker with NGINX for Laravel PART 1

Our folder structure will be as follows:

We will create configurations for both DEV and PROD environments, including HTTP and HTTPS with SSL certificates and key.

SETUP FOR DEV

nginx.dockerfile

FROM nginx:stable-alpine — we are going to use the latest nginx version from alpine linux

ENV — creates a variable inside the file

RUN mkdir -p /var/www/html/public — we are creating a public folder in the NGINX filesystem

ADD ../../nginx/default.conf /etc/nginx/conf.d/default.conf — we are copying our local nginx configuration to NGINX

RUN sed -i “s/user www-data/user ${NGINXUSER}/g” /etc/nginx/nginx.conf — we are searching for “user www-data” and replace it with “user laravel”

RUN adduser -g ${NGINXGROUP} -s /bin/sh -D ${NGINXUSER} — we are creating a new user (“laravel”) and add its profile to the shell and set no password (-D for Alpine)

default.conf

This is just a boilerplate configuration for NGINX web servers. You can create yours easily here.

On this configuration only HTTP is set up.

SETUP FOR PROD

nginx.prod.dockerfile

This configuration is similar as the one before, the only difference is that we ADD both laravel-docker.test.pem and laravel-docker.test-key.pem from our local machine to the NGINX web server.

Here is how you can generate your SSL certificates.

default.prod.conf

And now we add HTTPS as well for the PROD configuration and a server name to access the server from.

We also tell NGINX that for HTTPS we are going to use SSL and where to get the files.

Checkout PART2 to setup PHP.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Coman Cosmin

Coman Cosmin

128 Followers

I convert real world problem into technical solutions. I do research and make robots.