nginx-boilerplate

Awesome Nginx configuration template

  • 所有者: nginx-boilerplate/nginx-boilerplate
  • 平台:
  • 许可证: MIT License
  • 分类:
  • 主题:
  • 喜欢:
    0
      比较:

Github星跟踪图

Nginx Boilerplate

Chat

Awesome Nginx configuration template and a set of handy must-have snippets.

Features

  • Expressive include-based config
  • Optimized defaults
  • Easy PHP integration
  • Connections/requests rate limiting and throttling
  • A-grade SSL setup
  • FastCGI response caching
  • Various predefined locations
  • Advanced logging
  • SEO
  • Docker/Swarm ready

Requirements

  • Docker >= 1.13
  • docker-compose >= 3.1

Configs themselves depend on Nginx >= 1.9.5, if used separately.

Usage

Abstract

Nginx boilerplate builds on top of official nginx and php alpine Docker images.
Additionally two basic docker-compose configs are provided: docker-compose.yml and docker-compose.override.yml.
The first contains the base/production version of the docker run config while the second transparently extends it to provide extra features for local development.
Only docker-compose.yml should be used in production.

docker-compose.override.yml also contains an empty php fpm installation for the sake of the demo. Also because the boilerplate assumes the usage of php-fpm and fails to start otherwise.

Check it out

You only need docker for this, simply run:

$ docker run --rm -it -p 80:80 -p 443:443 nginxboilerplate/nginx-boilerplate

Now open up https://localhost/go/home in your browser!

And since you only run the nginx part there, there's no support for php.
If you open the main page, which supposed to give you the phpinfo output, it's going to load for 10 secods and give you an error page.

Running it

For a quick and dirty localhost setup run:

$ docker-compose up -d

By default the bundled nginx image is provided with self-signed wildcard certificate for *.localhost, so you will have to instruct your browser to trust it.

Reloading

To not have to restart containers each time you modify your configs, you can simply run:

$ docker-compose exec nginx nginx -s reload

Logs

By default a new logs/ directory should be created in the project directory, that directly maps to the nginx logs directory.

Docker swarm

To run in Docker swarm first make sure your Docker setup is in swarm mode:

$ docker swarm init

First of all you need to define your domain ssl certificate and key as a swarm secret:

$ docker secret create cert.crt your_certificate.crt
$ docker secret create cert.key your_certificate_key.key

Now to start or update nginx (and php) services in the swarm run:

$ docker stack deploy -c docker-compose.yml --with-registry-auth --prune app

To see nginx logs run:

$ docker service logs -f app_nginx

To scale services:

$ docker service scale app_nginx=2 app_fpm=10

Now you can refresh the page a couple of times and notice different host names that your requests land on.

Customization

The main virtual host definition is located at servers/main.conf.
Probably the best way to work with the repo is by cloning it and hooking up docker hub to automatically build a new image whenever there's new code.

If something doesn't work

主要指标

概览
名称与所有者nginx-boilerplate/nginx-boilerplate
主编程语言Dockerfile
编程语言Dockerfile (语言数: 1)
平台
许可证MIT License
所有者活动
创建于2013-06-04 22:05:46
推送于2018-07-26 19:54:37
最后一次提交2018-07-26 21:54:37
发布数14
最新版本名称1.2.0 (发布于 )
第一版名称v0.1.0 (发布于 )
用户参与
星数2.4k
关注者数121
派生数196
提交数213
已启用问题?
问题数65
打开的问题数1
拉请求数25
打开的拉请求数0
关闭的拉请求数2
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?