Giter VIP home page Giter VIP logo

nginx-config-boilerplate's Introduction

Nginx Config Boilerplate

Modular Nginx config for modern, secure sites in 2018 2019 2020 2021 2022 2023.

凭谁问:廉颇老矣,尚能饭否?——辛弃疾

This project aims to be a modular Nginx config template to ease common tasks like proxying websites, redirecting URLs, (semi-automatically) signing Let's Encrypt, offloading SSL, etc.

Compatibility

We assume you are always using the newest mainline version of Nginx with at least the official sets of modules. Some new exciting features (http2, stream, etc.) are not supported on old versions (stable and/or distro packages).

Here is instruction for installing latest version of nginx.

Compatibility with other Nginx-derived projects (OpenResty, etc.) and 3rd party modules are not verifyed. If you have interest in verifying with/supporting them, contributions are welcomed.

Installation

If you already have production sites running on Nginx, don't do anything stupid. You should only take essential pieces from here and evaluate your own config on staging environment.

If you are starting with a clean Nginx installation without any custom config, you can directly replace your nginx config sketelon with this one:

# run as root
rm -r /etc/nginx
git clone https://github.com/Jamesits/nginx-config-boilerplate.git /etc/nginx
cd /etc/nginx
./helper_scripts/kickstart.sh

mkdir -p /etc/systemd/system/nginx.service.d
cat > /etc/systemd/system/nginx.service.d/override.conf <<EOF
[Service]
LimitNOFILE=1048576
EOF
systemctl stop nginx
systemctl daemon-reload
systemctl enable --now nginx

Usage

Directory Structure

  • conf.d/*.conf is where your HTTP/HTTPS config lives
  • stream.conf.d/*.conf is for TCP proxy

There are various examples/*.conf files in these two directory; you can use them as a start point (copy it to conf.d/ or stream.conf.d/ and rename them) and modify it to suit your needs. Basically you need to change these values:

  • server_name to your domain (set up DNS to point to your server IP!)
  • proxy_pass to your backend or what you want to proxy from
  • ssl_certificate and ssl_certificate_key to your SSL key file (If you use certbot then you may only need to edit example.com part)

Updating

Sometimes this config skeleton might change, for example, when old TLS configuration is deprecated. To update:

# run as root
cd /etc/nginx
./helper_scripts/update.sh

Semi-automatic Let's Encrypt signing

We implemented a semi-automatic LE signing method with no service disruption during signing process. This require certbot be installed and auto renew timer is configured correctly on your system.

To get a TLS cert:

# run as root
cd /etc/nginx
./helper_scripts/letsencrypt.sh your.domain.example.com

Notes

If you think this is helpful, please consider buy me a coffee.

This config template is originated from a production server (One of my load balancers running Ubuntu 16.04). They are based on the official config template of Nginx 1.12.

Some fossil versions of Nginx uses a different directory structure:

  • /etc/nginx/sites-available/*.conf to store all sites configuration;
  • /etc/nginx/sites-enabled/*.conf are symlinks from sites-available and they are actually included in the main config.

We do not use this structure anymore, and conf.d/ works exactly the same like sites-enabled/ (though without the symlinks). If you want to temporary disable a config just append a .disabled on its name (other suffixes are fine as long as the last part of the file name is not .conf).

nginx-config-boilerplate's People

Contributors

jamesits avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

lbalak50

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.