nginx image based on official nginx image. Provided by MobiDev
10K+
Extended Official NGINX Docker Image
All images are based on Official NGINX Docker Image with stable-alpine and mainline-alpine tags
Maintained by: MobiDev
Supported architectures: linux/amd64, linux/arm64
Additional modules (not available in official nginx image):
List of all available modules:
docker run --rm mobidevpublisher/nginx:stable ls /etc/nginx/modules
Predefined templates help you to configure nginx with most common cases
List of all available predefined templates
docker run --rm mobidevpublisher/nginx:stable ls /etc/nginx/predefined_templates
What's inside template?
docker run --rm mobidevpublisher/nginx:stable cat /etc/nginx/predefined_templates/symfony.conf.template
By default, this image reads all template files in /etc/nginx/predefined_templates/*.template and outputs the result to /etc/nginx/conf.d and so it means that instead of choosing between predefined templates you are free to use your own *.conf.template file.
Here is an example of using docker-compose.yml:
nginx:
image: mobidevpublisher/nginx:stable
environment:
NGINX_PREDEFINED_TEMPLATE: custom.conf.template
NGINX_SERVER_NAME: "localhost"
NGINX_PORT: 8085
NGINX_ROOT: /var/www/app/public
PHP_HOST: php
PHP_PORT: 9000
volumes:
- ./templates/custom.conf.template:/etc/nginx/predefined_templates/custom.conf.template
ports:
- "8085:8085"
expose:
- "8085"
docker run --rm -v "${PWD}:/var/www/html" -e NGINX_PORT=8085 -e NGINX_SERVER_NAME=localhost -e NGINX_ROOT=/var/www/html -e NGINX_PREDEFINED_TEMPLATE=default.conf.template -p 8085:8085 mobidevpublisher/nginx:stable
Docker Compose example for Nginx, PHP (Symfony Framework)
version: '3.5'
services:
nginx:
env_file:
- .env
image: mobidevpublisher/nginx:stable
environment:
NGINX_PREDEFINED_TEMPLATE: "symfony.conf.template"
NGINX_SERVER_NAME: "localhost"
NGINX_PORT: 8085
NGINX_ROOT: /var/www/app/public
PHP_HOST: php
PHP_PORT: 9000
working_dir: /var/www/app
volumes:
- ".:/var/www/app"
networks:
- local
depends_on:
- php
ports:
- "8085:8085"
expose:
- "8085"
php:
env_file:
- .env
working_dir: /var/www/app
image: mobidevpublisher/php:7.4.33
environment:
PHP_ENABLED_EXTENSIONS: "amqp apcu opcache xdebug mcrypt sodium redis zip pdo_pgsql gd gmp"
PHP_ALLOW_URL_FOPEN: "On"
PHP_MAX_EXECUTION_TIME: 60
PHP_MAX_INPUT_TIME: 60
PHP_MEMORY_LIMIT: "128M"
PHP_POST_MAX_SIZE: "120M"
PHP_UPLOAD_MAX_FILESIZE: "100M"
PHP_SHORT_OPEN_TAG: "On"
PHP_DISPLAY_ERRORS: "On"
PHP_DISPLAY_STARTUP_ERRORS: "On"
volumes:
- ".:/var/www/app"
networks:
- local
networks:
local:
name: local
Docker Compose example for Nginx with Nchan
version: '3.5'
services:
nchan:
image: mobidevpublisher/nginx:stable
restart: on-failure
environment:
NGINX_PREDEFINED_TEMPLATE: "nchan.conf.template"
NGINX_SERVER_NAME: localhost
NGINX_PORT: 8088
NCHAN_SUBSCRIBER_ENDPOINT: "/sub"
NCHAN_PUBLISHER_ENDPOINT: "/pub"
networks:
- local
ports:
- 8088:8088
networks:
local:
name: local
Create a Dockerfile
FROM mobidevpublisher/nginx:1.24
COPY ./nginx_configs/ /etc/nginx
COPY ./html/ /var/www/html
WORKDIR /var/www/html
Build and run the Docker image
docker build -t my-nginx .
docker run -it --rm --name my-running-nginx my-nginx
There are Predefined templates with SSL configuration
List of all available predefined SSL templates
docker run --rm mobidevpublisher/nginx:stable ls /etc/nginx/predefined_templates/ | grep ssl_
You need to obtain SSL Certificate from any Certificate Authority (Paid certificates)
Another option is to use Free SSL from Let's Encrypt
Both options will work with Nginx configuration
Also, you need to generate DH parameters to make your SSL encryption stronger
How to generate dhparam.pem file
openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048
You need to obtain SSL certificate from Let's Encrypt.
Create a volume where obtained certificates will be stored and then run certbot docker container with required parameters
Note: certbot requires 80 port
docker volume create --name=letsencrypt-etc
docker run -it --rm -v letsencrypt-etc:/etc/letsencrypt \
-p 80:80 \
certbot/certbot \
certonly \
--standalone \
-n -m [email protected] \
--agree-tos \
-d example.com
Note: you can add those commands to cron and renew certificates
We can run docker-compose with attached volume with certificates
version: '3.5'
services:
nginx:
image: mobidevpublisher/nginx:stable
environment:
NGINX_PREDEFINED_TEMPLATE: "ssl_static.conf.template"
NGINX_SERVER_NAME: "example.com"
NGINX_PORT: 80
NGINX_ROOT: /var/www/html
NGINX_SSL_PORT: "443 ssl http2"
PATH_TO_SSL_CERTIFICATE_FILE: "/etc/letsencrypt/live/example.com/fullchain.pem"
PATH_TO_SSL_CERTIFICATE_KEY_FILE: "/etc/letsencrypt/live/example.com/privkey.pem"
PATH_TO_SSL_DHPARAM_FILE: "/etc/nginx/ssl/dhparam.pem"
working_dir: /var/www/html
volumes:
- ".:/var/www/html"
- "./dhparam.pem:/etc/nginx/ssl/dhparam.pem"
- "letsencrypt:/etc/letsencrypt"
networks:
- local
depends_on:
- php
ports:
- "80:80"
- "443:443"
expose:
- "80"
- "443"
volumes:
letsencrypt:
external:
name: letsencrypt-etc
Test your SSL configuration with SSL Server Test
Most environment variables depend on template you are going to use. Some variables are required, but some are optional. For example variables for Basic access authentication are optional
Specify predefined template that you are going to use.
How it works? Specified predefined template will be copied to nginx templates directory /etc/nginx/templates (by default) After that initial startup script will substitute all required environment variables, and you are good to go with your nginx configuration
List of all available predefined templates
docker run --rm mobidevpublisher/nginx:stable ls /etc/nginx/predefined_templates
What's inside template?
docker run --rm mobidevpublisher/nginx:stable cat /etc/nginx/predefined_templates/symfony.conf.template
Example value: "php.conf.template"
http://nginx.org/en/docs/http/ngx_http_core_module.html#listen
Example value: 80
http://nginx.org/en/docs/http/ngx_http_core_module.html#root
Example value: /var/www/app/
http://nginx.org/en/docs/http/ngx_http_core_module.html#server_name
Example value: "example.com"
Set host for php upstream
Example value: php
Required in templates with PHP support
Set port for php upstream
Example value: 9000
Required in templates with PHP support
Username for Basic access authentication
Example value: "username"
Password for Basic access authentication
Example value: "your$ecretpassword"
Path to Basic access authentication file where username and password will be stored
Example value: "/etc/nginx/.htpasswd-users"
http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass
Example value: "http://adminer:8080"
Required in templates with proxy configuration. For example "proxy.conf.template"
http://nginx.org/en/docs/http/ngx_http_rewrite_module.html#return
Example value: 307
Required in templates with redirect configuration. For example "redirect.conf.template"
http://nginx.org/en/docs/http/ngx_http_rewrite_module.html#return
Example value: example.com
Required in templates with redirect configuration. For example "redirect.conf.template"
http://nginx.org/en/docs/http/ngx_http_core_module.html#listen
Example value: "443 ssl http2"
http://nginx.org/en/docs/http/ngx_http_ssl_module.html#ssl_certificate
Example value: /etc/letsencrypt/live/example.com/fullchain.pem
http://nginx.org/en/docs/http/ngx_http_ssl_module.html#ssl_certificate_key
Example value: /etc/letsencrypt/live/example.com/privkey.pem
http://nginx.org/en/docs/http/ngx_http_ssl_module.html#ssl_dhparam
Example value: /etc/nginx/ssl/dhparam.pem
mobidevpublisher/nginx:
Examples:
docker pull mobidevpublisher/nginx:mainline
docker pull mobidevpublisher/nginx:stable
docker pull mobidevpublisher/nginx:1.24.0
List of all available tags
The MIT License
Copyright (c) 2009-2023 MobiDev Corporation [email protected]
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Content type
Image
Digest
sha256:cf6583d6e…
Size
25.4 MB
Last updated
1 day ago
docker pull mobidevpublisher/nginx