Giter Club home page Giter Club logo

nginx-snippets's Introduction

NGINX Snippets

A collection of NGINX snippets designed to be used for hosting multiple Node.js servers.

I use these settings behind Cloudflare to provide Full (strict) end-to-end encryption. Using a Cloudflare Origin CA certificate is the easiest way to accomplish this, although this certificate is not trusted by clients; meaning you must use a different certificate issued by CA (such as Let's Encrypt) in order to server traffic that does not pass through Cloudflare.

For other NGINX setups, Digital Ocean's NGINXConfig tool is a great place to start.

Configuration files

nginx.conf /etc/nginx/nginx.conf

Base server settings that:

  • Set-up logging.
  • Import other config files.
  • Specifies TLS settings.
  • Provides variables for other configuration files.

headers.conf /etc/nginx/conf.d/headers.conf

Adds general security headers to all requests.

  • Restrictive CORS & permissions policy
  • iFrame blocking
  • Tracking blocking

Note: these headers include HSTS, meaning if you don't plan to support HTTPS on all hosted sites now and into the future, you must remove this header.

ssl.conf /etc/nginx/sites-enabled/ssl.conf

Force all HTTP connections to retry via HTTPS. Subsequently, all other NGINX server blocks should listen on port 443.

By default, a certificate at /etc/ssl/certs/certificate.pem with a key at /etc/ssl/private/certificate.key are used. These names and locations can of course be changed.

If multiple certificates are needed for various domains, the default certificate can be overridden inside a server block using the following snippet.

ssl_certificate /etc/ssl/certs/other-cert.pem;
ssl_certificate_key /etc/ssl/private/other-cert.key;

timeout.conf /etc/nginx/conf.d/timeout.conf

Configures various request and response timeouts to be 30 seconds.

proxy-params.conf /etc/nginx/snippets/proxy-params.conf

Various proxy parameters that ensure information is correctly passed to the server to be included in each proxy server location block.

Example server block usage /etc/nginx/sites-enabled/example.com

Route requests to the domain example.com to the server running locally on the port 9000.

server {
    listen 443;

    server_name subdomain.example.com example.com;
    
    location / {
        proxy_pass http://127.0.0.1:9000;
        include /etc/nginx/snippets/proxy-params.conf;
    }
}

nginx-snippets's People

Contributors

angablue avatar

Stargazers

 avatar  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.