Top Related Projects
The official NGINX Open Source repository.
⚙️ NGINX config generator on steroids 💉
How to improve NGINX performance, security, and other important things.
A collection of resources covering Nginx, Nginx + Lua, OpenResty and Tengine
NGINX tuning for best performance
Nginx Block Bad Bots, Spam Referrer Blocker, Vulnerability Scanners, User-Agents, Malware, Adware, Ransomware, Malicious Sites, with anti-DDOS, Wordpress Theme Detector Blocking and Fail2Ban Jail for Repeat Offenders
Quick Overview
The h5bp/server-configs-nginx repository is a collection of best practices and configuration snippets for Nginx web servers. It aims to improve the performance, security, and reliability of web applications by providing optimized Nginx configurations that can be easily implemented and customized.
Pros
- Comprehensive set of configurations covering various aspects of web server optimization
- Well-documented and regularly maintained by the community
- Easily adaptable to different project requirements
- Includes configurations for popular web applications and frameworks
Cons
- May require advanced knowledge of Nginx to fully understand and implement all configurations
- Some configurations might not be suitable for all use cases and could require modifications
- Potential performance impact if all configurations are applied without consideration for specific needs
- Regular updates may require periodic review and adjustment of existing configurations
Code Examples
- Enabling GZIP compression:
gzip on;
gzip_comp_level 5;
gzip_min_length 256;
gzip_proxied any;
gzip_vary on;
gzip_types
application/atom+xml
application/javascript
application/json
application/ld+json
application/manifest+json
application/rss+xml
application/vnd.geo+json
application/vnd.ms-fontobject
application/x-font-ttf
application/x-web-app-manifest+json
application/xhtml+xml
application/xml
font/opentype
image/bmp
image/svg+xml
image/x-icon
text/cache-manifest
text/css
text/plain
text/vcard
text/vnd.rim.location.xloc
text/vtt
text/x-component
text/x-cross-domain-policy;
- Implementing browser caching:
location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
expires 1y;
add_header Cache-Control "public, max-age=31536000";
}
- Enabling HSTS (HTTP Strict Transport Security):
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;
Getting Started
-
Clone the repository:
git clone https://github.com/h5bp/server-configs-nginx.git
-
Copy the desired configuration files to your Nginx configuration directory:
cp -R server-configs-nginx/h5bp /etc/nginx/
-
Include the configurations in your
nginx.conf
or site-specific configuration:include h5bp/basic.conf; include h5bp/security/server_software_information.conf;
-
Test the configuration and restart Nginx:
nginx -t systemctl restart nginx
Competitor Comparisons
The official NGINX Open Source repository.
Pros of nginx
- Official repository with the most up-to-date source code
- Comprehensive documentation and extensive community support
- Allows for custom module development and deep system-level customization
Cons of nginx
- Requires more technical expertise to configure and optimize
- Less focus on pre-configured, ready-to-use server configurations
- May require additional effort to implement best practices for security and performance
Code Comparison
nginx:
server {
listen 80;
server_name example.com;
root /var/www/example.com;
index index.html;
}
server-configs-nginx:
server {
listen [::]:80;
listen 80;
server_name example.com;
root /var/www/example.com;
include h5bp/basic.conf;
}
Summary
nginx is the official repository for the NGINX web server, offering the latest source code and extensive customization options. It's ideal for users who need fine-grained control over their server configuration.
server-configs-nginx provides pre-configured, production-ready NGINX configurations with a focus on security and performance best practices. It's more suitable for users who want a quick setup with optimized settings out of the box.
The choice between the two depends on the user's needs, technical expertise, and desired level of customization. server-configs-nginx offers a more streamlined approach, while nginx provides greater flexibility for advanced users.
⚙️ NGINX config generator on steroids 💉
Pros of nginxconfig.io
- User-friendly web interface for generating NGINX configurations
- Provides a visual approach to configuration, making it easier for beginners
- Offers real-time preview and downloadable configuration files
Cons of nginxconfig.io
- Limited to predefined configuration options
- May not cover all advanced NGINX features or custom setups
- Requires internet access to use the tool
Code Comparison
server-configs-nginx:
location ~* \.(?:manifest|appcache|html?|xml|json)$ {
expires -1;
}
location ~* \.(?:rss|atom)$ {
expires 1h;
}
nginxconfig.io (generated output):
location ~* \.(?:manifest|appcache|html?|xml|json)$ {
expires off;
}
location ~* \.(?:rss|atom)$ {
expires 1h;
}
Summary
server-configs-nginx provides a comprehensive set of NGINX configuration examples and best practices, suitable for advanced users who prefer direct control over their server setup. It offers a wide range of optimizations and security enhancements.
nginxconfig.io, on the other hand, focuses on simplifying the configuration process through a web-based interface. It's ideal for users who want a quick and easy way to generate NGINX configurations without delving into the intricacies of the syntax.
Both projects aim to improve NGINX configuration, but they cater to different user needs and skill levels.
How to improve NGINX performance, security, and other important things.
Pros of nginx-admins-handbook
- More comprehensive coverage of NGINX configuration topics
- Includes detailed explanations and best practices
- Offers troubleshooting guides and performance optimization tips
Cons of nginx-admins-handbook
- Less focused on ready-to-use configuration files
- May be overwhelming for beginners due to its extensive content
- Requires more time to navigate and implement specific configurations
Code Comparison
server-configs-nginx:
location ~* \.(?:manifest|appcache|html?|xml|json)$ {
expires -1;
}
nginx-admins-handbook:
location ~* \.(css|js|jpg|jpeg|png|gif|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
expires 1M;
access_log off;
add_header Cache-Control "public";
}
The server-configs-nginx example focuses on disabling caching for specific file types, while the nginx-admins-handbook example demonstrates setting cache expiration and headers for static assets.
Both repositories offer valuable resources for NGINX configuration. server-configs-nginx provides a more straightforward approach with ready-to-use configurations, making it ideal for quick implementation. nginx-admins-handbook, on the other hand, offers a deeper dive into NGINX administration, making it suitable for those seeking a comprehensive understanding of NGINX and its advanced features.
A collection of resources covering Nginx, Nginx + Lua, OpenResty and Tengine
Pros of nginx-resources
- Comprehensive collection of NGINX resources, including articles, books, and tools
- Regularly updated with new content and community contributions
- Covers a wide range of NGINX-related topics, from basic configuration to advanced use cases
Cons of nginx-resources
- Lacks ready-to-use configuration files for immediate implementation
- Requires more time and effort to find specific solutions among the vast resources
- May be overwhelming for beginners due to the sheer amount of information
Code comparison
server-configs-nginx provides practical configuration examples:
location ~* \.(?:manifest|appcache|html?|xml|json)$ {
expires -1;
}
nginx-resources doesn't include direct code snippets but links to resources:
- [Nginx Tutorials](https://github.com/agile6v/awesome-nginx) - A curated list of Nginx tutorials.
Summary
server-configs-nginx offers ready-to-use NGINX configurations for various scenarios, making it ideal for quick implementation. nginx-resources, on the other hand, provides a comprehensive collection of NGINX-related resources, including articles, tools, and tutorials. While it requires more effort to find specific solutions, it offers a broader range of information and keeps users updated with the latest NGINX developments.
NGINX tuning for best performance
Pros of nginx-tuning
- Focuses specifically on performance optimization and tuning
- Provides more detailed explanations of configuration options
- Includes benchmarking tools and results
Cons of nginx-tuning
- Less comprehensive in terms of general server configuration
- Not as actively maintained or updated
- Fewer contributors and community involvement
Code Comparison
server-configs-nginx:
location ~* \.(?:manifest|appcache|html?|xml|json)$ {
expires -1;
}
location ~* \.(?:rss|atom)$ {
expires 1h;
}
nginx-tuning:
worker_processes auto;
worker_rlimit_nofile 100000;
events {
worker_connections 2048;
use epoll;
multi_accept on;
}
The server-configs-nginx example focuses on caching and expiration settings for different file types, while the nginx-tuning example emphasizes worker process configuration and event handling for improved performance.
Both repositories offer valuable insights into Nginx configuration, but they serve different purposes. server-configs-nginx provides a more comprehensive set of configurations for various scenarios, while nginx-tuning concentrates on performance optimization. Users should consider their specific needs when choosing between the two, or potentially combine insights from both repositories for a well-rounded Nginx setup.
Nginx Block Bad Bots, Spam Referrer Blocker, Vulnerability Scanners, User-Agents, Malware, Adware, Ransomware, Malicious Sites, with anti-DDOS, Wordpress Theme Detector Blocking and Fail2Ban Jail for Repeat Offenders
Pros of nginx-ultimate-bad-bot-blocker
- Comprehensive bot and spam protection with an extensive blocklist
- Regular updates to the blocklist to combat new threats
- Includes protection against referrer spam and fake crawlers
Cons of nginx-ultimate-bad-bot-blocker
- May require more configuration and customization
- Potential for false positives, blocking legitimate traffic
- Focuses primarily on bot blocking, less on general server configuration
Code Comparison
nginx-ultimate-bad-bot-blocker:
if ($bad_bot = 1) {
return 444;
}
if ($bad_referer = 1) {
return 403;
}
server-configs-nginx:
location ~* \.(?:manifest|appcache|html?|xml|json)$ {
expires -1;
}
location ~* \.(?:rss|atom)$ {
expires 1h;
}
The nginx-ultimate-bad-bot-blocker focuses on bot detection and blocking, while server-configs-nginx provides more general server optimization and security configurations. The former is ideal for sites facing bot attacks, while the latter offers a broader set of best practices for NGINX configuration. server-configs-nginx may be easier to implement for beginners, but nginx-ultimate-bad-bot-blocker provides more specialized protection against malicious bots and spam.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Nginx Server Configs
Nginx Server Configs is a collection of configuration files that can help your server improve the website's performance and security, while also ensuring that resources are served with the correct content-type and are accessible, if needed, even cross-domain.
Getting Started
Using the Nginx server configs repo directly has a few required steps to be able to work.
Check nginx.conf
settings
The first thing to check is that the nginx.conf
file contains appropriate values for
your specific install.
Most specific variables are:
user
error_log
pid
access_log
Nginx test and restart
-
To verify Nginx config
nginx -t
-
To verify Nginx config with a custom file
nginx -t -c nginx.conf
-
To reload Nginx and apply the new config
nginx -s reload
Repository structure
This repository has the following structure:
./
âââ conf.d/
â âââ default.conf
â âââ templates/
âââ h5bp/
â âââ basic.conf
â âââ location/
â âââ .../
âââ custom.d/
â âââ .../
âââ mime.types
âââ nginx.conf
-
conf.d/
This directory should contain all the
server
definitions.Except if they are dot prefixed or non
.conf
extension, all files in this directory are loaded automatically.-
templates
folderFiles in this directory contain a
server
template for secure and non-secure hosts. They are intended to be copied in theconf.d
directory with allexample.com
occurrences changed to the target host.
-
-
h5bp/
This directory contains config snippets (mixins) to be included as desired.
There are two types of config files provided: individual config snippets and combined config files which provide convenient defaults.
-
basic.conf
This file loads a small subset of the rules provided by this repository to add
expires
headers, allow cross-domain fonts and protect system files from web access. Thebasic.conf
file includes the rules which are recommended to always be defined. -
location/
Files in this directory contain one or more
location
directives. They are intended to be loaded in theserver
context (or, in a nestedlocation
block).
-
-
custom.d/
This directory should contain all the custom
nginx.conf
configuration.Except if they are dot prefixed or non
.conf
extension, all files in this folder are loaded automatically. -
mime.types
The
mime.types
file is responsible for mapping file extensions to MIME types. -
nginx.conf
The main Nginx config file.
Usage
As a reference
To use as reference requires no special installation steps, download/checkout the repository to a convenient location and adapt your existing Nginx configuration incorporating the desired functionality from this repository.
Download the latest release archive.
Directly
To use directly, replace the Nginx config directory with this repository. For example:
nginx -s stop
cd /etc
mv nginx nginx-previous
git clone https://github.com/h5bp/server-configs-nginx.git nginx
# install-specific edits
nginx
Manage sites
cd /etc/nginx/conf.d
-
Creating a new site
cp templates/example.com.conf .actual-hostname.conf sed -i 's/example.com/actual-hostname/g' .actual-hostname.conf
-
Enabling a site
mv .actual-hostname.conf actual-hostname.conf
-
Disabling a site
mv actual-hostname.conf .actual-hostname.conf
nginx -s reload
Support
- Nginx v1.8.0+
Contributing
Anyone is welcome to contribute, however, if you decide to get involved, please take a moment to review the guidelines:
Acknowledgements
Nginx Server Configs is only possible thanks to all the awesome contributors!
License
The code is available under the MIT license.
Top Related Projects
The official NGINX Open Source repository.
⚙️ NGINX config generator on steroids 💉
How to improve NGINX performance, security, and other important things.
A collection of resources covering Nginx, Nginx + Lua, OpenResty and Tengine
NGINX tuning for best performance
Nginx Block Bad Bots, Spam Referrer Blocker, Vulnerability Scanners, User-Agents, Malware, Adware, Ransomware, Malicious Sites, with anti-DDOS, Wordpress Theme Detector Blocking and Fail2Ban Jail for Repeat Offenders
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot