Last active
May 7, 2018 07:32
-
-
Save jasperf/323ce44872fec673b908cc89ab11ae3e to your computer and use it in GitHub Desktop.
Dockerfile Nginx with SSL Setup using commercial certificates (Laradock based)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### NGINX Server ######################################### | |
nginx: | |
build: | |
context: ./nginx | |
args: | |
- PHP_UPSTREAM_CONTAINER=${NGINX_PHP_UPSTREAM_CONTAINER} | |
- PHP_UPSTREAM_PORT=${NGINX_PHP_UPSTREAM_PORT} | |
volumes: | |
- ${APP_CODE_PATH_HOST}:${APP_CODE_PATH_CONTAINER} | |
- ${NGINX_HOST_LOG_PATH}:/var/log/nginx | |
- ${NGINX_SITES_PATH}:/etc/nginx/sites-available | |
- ${HOST_PATH_TO_CERTS}:${CONTAINER_PATH_TO_CERTS} | |
ports: | |
- "${NGINX_HOST_HTTP_PORT}:80" | |
- "${NGINX_HOST_HTTPS_PORT}:443" | |
depends_on: | |
- php-fpm | |
networks: | |
- frontend | |
- backend |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM nginx:alpine | |
LABEL maintainer="Mahmoud Zalt <mahmoud@zalt.me>" | |
COPY nginx.conf /etc/nginx/ | |
# If you're in China, or you need to change sources, will be set CHANGE_SOURCE to true in .env. | |
ARG CHANGE_SOURCE=false | |
RUN if [ ${CHANGE_SOURCE} = true ]; then \ | |
# Change application source from dl-cdn.alpinelinux.org to aliyun source | |
sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/' /etc/apk/repositories \ | |
;fi | |
RUN apk update \ | |
&& apk upgrade \ | |
&& apk add --no-cache bash \ | |
&& adduser -D -H -u 1000 -s /bin/bash www-data | |
# install openssl | |
RUN apk add --no-cache openssl | |
# create a folder for the keys | |
RUN mkdir /etc/nginx/ssl 2> /dev/null | |
# # generate the keys for your local development set up | |
# RUN openssl genrsa -out "/etc/nginx/ssl/domain.key" 2048 \ | |
# && openssl req -new -key "/etc/nginx/ssl/domain.key" -out "/etc/nginx/ssl/domain.csr" -subj "/CN=domain/O=domain/C=NL" \ | |
# && openssl x509 -req -days 365 -in "/etc/nginx/ssl/domain.csr" -signkey "/etc/nginx/ssl/domain.key" -out "/etc/nginx/ssl/domain.crt" | |
ARG PHP_UPSTREAM_CONTAINER=php-fpm | |
ARG PHP_UPSTREAM_PORT=9000 | |
# Set upstream conf and remove the default conf | |
RUN echo "upstream php-upstream { server ${PHP_UPSTREAM_CONTAINER}:${PHP_UPSTREAM_PORT}; }" > /etc/nginx/conf.d/upstream.conf \ | |
&& rm /etc/nginx/conf.d/default.conf | |
CMD ["nginx"] | |
EXPOSE 80 443 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment