Giter Club home page Giter Club logo

docker-alpine-nginx's Introduction

hellifiknow/nginx-php7

This is a Docker image to use as a web server with Nginx and PHP 7.1.
Nginx and PHP are both preconfigured and ready to handle your connections.

PHP includes the following modules:

  • json
  • gd
  • curl
  • opcache
  • pdo_mysql
  • mbstring
  • session
  • openssl

Simple usage

Just start it with docker run -d -p 80:80 -v .:/app hellifiknow/nginx-php7 to use the current path as webroot.

I want to add rules in the nginx configuration

Following folders include *.conf files automatically:

  • /etc/nginx/modules: included at the start of the root nginx configuration,
  • /etc/nginx/servers: included at the end of the http block,
  • /etc/nginx/locations: included at the start of the server block, for normal requests,
  • /etc/nginx/locations/no_domain: included at the start of the server block, for requests with no server_name match,
  • /etc/nginx/locations/http: included at the start of the server block, for http requests only with HTTPS=force.

To print and debug your nginx configuration, you can simply run docker exec <container_name> nginx -T.

I want to change the full nginx configuration

All nginx server configuration blocks are stored in /etc/nginx/servers/*.conf. If you want to edit the default configuration, or add another one, create a file in your project like this one:

server {
	listen 80 default_server;
	root "/app";
	
	...
}

then add in your Dockerfile COPY my_custom.conf /etc/nginx/servers/default.conf.

More custom usage

To extends the image, use the onbuild version that runs the install files in the extended image. E.g. the sample project nginx-php7-laravel.
A minimalistic Dockerfile to change the STATIC_DIR would be:

FROM hellifiknow/nginx-php7:onbuild
ARG STATIC_DIR=public
RUN /bin/sh /install/install.sh

The following configurations can be changed with build args:

APP_DIR

Application file directory, default to /app

STATIC_DIR

Document root in APP_DIR.
With STATIC_DIR=public, the url http://host/ will fetch /app/public/index.php.
Default to APP_DIR root.

USER

User and group running nginx/php process

HTTPS

Possible values are:

  • off: Only listen for http.
  • on: Listen for http and https.
  • force: Listen for http and https, and redirect http to https.

Certificates must be placed as /etc/nginx/ssl/fullchain.pem and /etc/nginx/ssl/privkey.pem.

DOMAINS

List of allowed domains. Space separated. Default to all. Required for the https to work.

RAM

Server RAM in MB to calculate worker numbers, etc. Be default it will take the builder's machine max RAM.

UPLOAD_MAX

Maximum upload file size in MB, default to 10MB

FAIL2BAN_ENABLED

Enable a fail2ban like script in lua (NOT the real fail2ban with iptable), inside the nginx conf.
After 5 401 response code, the ip address is banned, and only 503 response code are returned.
Possible values are:

  • on: enabled on every pages, catch every 401 everywhere,
  • off: disabled,
  • manual: insert "include /etc/nginx/fail2ban/check.conf" in locations you want protect. Default to off.
FAIL2BAN_BLACKLIST_URL

Fail2ban blacklist admin url, used as nginx "location $here {", so you can use regex, e.g. "~ /bl[ao]cklist".
To insert it manually: "include /etc/nginx/fail2ban/api.conf".

FAIL2BAN_BLACKLIST_BASIC_AUTH

Fail2ban blacklist admin url's auth, in format user:password.

COUNTRY_WHITELIST / COUNTRY_BLACKLIST

Prevent/allow access from some countries. Space separated country codes.
E.g. to block top 10 hacker countries use COUNTRY_BLACKLIST=CN US TR RU TW BR RO IN IT HU. To whitelist local ips and France use COUNTRY_WHITELIST=FR ''

docker-alpine-nginx's People

Contributors

blunt1337 avatar hellifiknow avatar jeffp42 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.