What is NGINX Plus?
NGINX Plus is the commercial version of the open-source NGINX software. It includes additional features, professional support, and advanced functionality that are not available in the free version. NGINX Plus is designed to provide enhanced performance, reliability, and security for web applications.
Key Features of NGINX Plus
-
Advanced Load Balancing:
- Session Persistence: Ensures that a user session is consistently directed to the same server.
- Dynamic Configuration: Allows for real-time updates to load balancing configurations without restarting NGINX.
-
Application Health Monitoring:
- Active Health Checks: Continuously monitors the health of backend servers and removes unhealthy ones from the load balancing pool.
- Detailed Metrics: Provides in-depth metrics and statistics for monitoring application performance.
-
Enhanced Security:
- JWT Authentication: Supports JSON Web Token (JWT) for secure API authentication.
- WAF (Web Application Firewall): Protects applications from common web vulnerabilities.
-
High Availability:
- Cluster Management: Supports high availability configurations with automatic failover.
- Session Draining: Gracefully removes servers from the load balancing pool without disrupting active sessions.
-
Advanced Caching:
- Content Caching: Provides advanced caching mechanisms to improve application performance.
- Cache Purging: Allows for selective purging of cached content.
-
Dynamic Configuration:
- API-driven Configuration: Enables dynamic updates to the NGINX configuration via a RESTful API.
Installing NGINX Plus
Prerequisites
- A valid NGINX Plus subscription.
- Access to the NGINX Plus repository.
Installation Steps
-
Add the NGINX Plus Repository:
sudo wget -P /etc/ssl/nginx/ https://cs.nginx.com/static/keys/nginx-repo.crt sudo wget -P /etc/ssl/nginx/ https://cs.nginx.com/static/keys/nginx-repo.key
-
Create the NGINX Plus Repository File:
sudo bash -c 'cat > /etc/yum.repos.d/nginx-plus.repo <<EOF [nginx-plus] name=nginx-plus baseurl=https://pkgs.nginx.com/plus/centos/\$releasever/\$basearch/ ssl_certificate=/etc/ssl/nginx/nginx-repo.crt ssl_certificate_key=/etc/ssl/nginx/nginx-repo.key gpgcheck=1 enabled=1 EOF'
-
Install NGINX Plus:
sudo yum install nginx-plus
-
Start NGINX Plus:
sudo systemctl start nginx sudo systemctl enable nginx
Basic Configuration
Configuration File Structure
The main configuration file for NGINX Plus is located at /etc/nginx/nginx.conf
. The structure is similar to the open-source version but includes additional directives and modules specific to NGINX Plus.
Example Configuration
http { upstream backend { server backend1.example.com; server backend2.example.com; } server { listen 80; location / { proxy_pass http://backend; health_check; } } }
Explanation
- upstream: Defines a group of backend servers.
- server: Configures a virtual server that listens on port 80.
- location: Specifies the location block for handling requests.
- proxy_pass: Forwards requests to the defined upstream group.
- health_check: Enables active health checks for the backend servers.
Practical Exercise
Exercise: Setting Up a Basic NGINX Plus Configuration
-
Objective: Configure NGINX Plus to load balance traffic between two backend servers with active health checks.
-
Steps:
- Install NGINX Plus following the installation steps provided.
- Create a new configuration file
/etc/nginx/conf.d/load_balancer.conf
with the following content:upstream backend { server backend1.example.com; server backend2.example.com; } server { listen 80; location / { proxy_pass http://backend; health_check; } }
- Test the configuration:
sudo nginx -t
- Reload NGINX Plus to apply the configuration:
sudo systemctl reload nginx
-
Solution:
- Ensure that the backend servers (
backend1.example.com
andbackend2.example.com
) are reachable. - Verify that NGINX Plus is correctly forwarding traffic and performing health checks.
- Ensure that the backend servers (
Common Mistakes and Tips
- Incorrect Repository Configuration: Ensure that the repository file is correctly configured with the proper SSL certificates.
- Health Check Failures: Verify that the backend servers are healthy and responding to health check requests.
- Configuration Errors: Always test the configuration with
nginx -t
before reloading to catch syntax errors.
Conclusion
In this section, we introduced NGINX Plus, its key features, and how to install and configure it. NGINX Plus offers advanced load balancing, enhanced security, and dynamic configuration capabilities that are essential for high-performance web applications. The next topic will delve deeper into advanced load balancing techniques with NGINX Plus.