NGINX Snippets

After configuring many servers to deploy Node.js applications, I felt the need to streamline the process. As such I've developed and published a collection of NGINX snippets tailored for hosting multiple Node.js servers behind Cloudflare's firewall/CDN. These configurations are designed to provide Full (strict) end-to-end encryption, ensuring secure and efficient communication between clients and servers.
As a quick refresher, NGINX is a popular reverse proxy that routes incoming requests to their respective destination. It also handles caching, load balancing and can even act as a mail server, making it a powerful tool for hosting a variety of apps on a single physical server.
Key Features
After cloning the respository into /etc/nginx/snippets
, the following snippets can be symlinked into the configuration folder to provide the following base functionality.
- Centralised Configuration: The
nginx.conf
file establishes base server settings, including logging setup, TLS configurations, and the inclusion of supplementary config files. - Enhanced Security Headers: The
headers.conf
snippet introduces general security headers to all requests, implementing restrictive CORS policies, iFrame blocking, and tracking prevention measures. - SSL Enforcement: With
ssl.conf
, all HTTP connections are redirected to HTTPS, utilizing certificates for secure communication. - Optimised Timeouts: The
timeout.conf
file configures various request and response timeouts to 30 seconds, balancing performance and resource utilization. - Proxy Parameters: The
proxy-params.conf
snippet ensures that essential information is correctly passed to the server within each proxy location block.
Example Usage:
To route requests to example.com
to a local Node.js server running on port 9000
, the following server block can be used:
1server {
2 listen 443;
3
4 server_name subdomain.example.com example.com;
5
6 location / {
7 proxy_pass http://127.0.0.1:9000;
8 include /etc/nginx/snippets/proxy-params.conf;
9 }
10}
This configuration ensures that incoming requests are securely handled and efficiently proxied to the appropriate Node.js server.
By leveraging these NGINX snippets, I've aimed to create a modular and secure approach to server configuration, facilitating easier management and scalability for multiple Node.js applications. These configurations make it the default to create robust solutions that enhance both security and performance in web server management.
For a detailed overview and access to the configuration files, please visit the GitHub repository.