Configuration Files Overview
Centmin Mod installs Nginx from source with a custom directory layout. Understanding where configuration files live is essential for managing your web server.
Main Configuration File
The primary Nginx configuration file controls global settings, worker processes, and includes all other config files:
/usr/local/nginx/conf/nginx.conf
Virtual Host Configs
Per-domain server block configurations are stored in the conf.d directory:
/usr/local/nginx/conf/conf.d/domain.com.conf
/usr/local/nginx/conf/conf.d/domain.com.ssl.conf
Key Directory Locations
| Path | Purpose |
|---|---|
| /usr/local/nginx/conf/ | Main config directory |
| /usr/local/nginx/conf/conf.d/ | Virtual host configs |
| /home/nginx/domains/ | Web document roots |
| /usr/local/nginx/logs/ | Nginx log files |
| /usr/local/nginx/html/ | Default document root |
Global Settings
The main nginx.conf contains global directives that control Nginx's behavior at the process level.
Worker Processes & Connections
Centmin Mod automatically sets worker_processes to match your CPU core count. The worker_connections directive determines how many simultaneous connections each worker can handle.
worker_processes auto;
worker_rlimit_nofile 260000;
events {
worker_connections 10240;
multi_accept on;
accept_mutex on;
accept_mutex_delay 200ms;
use epoll;
}
Keepalive Settings
Keepalive connections allow multiple HTTP requests over a single TCP connection, reducing latency:
keepalive_timeout 10;
keepalive_requests 500;
Centmin Mod's default nginx.conf is already optimized for performance. Only modify these values if you understand the impact on your server's resource usage.
Virtual Host Configuration
Each website on your server gets its own Nginx server block (virtual host). Centmin Mod creates these automatically when you add a new Nginx vhost via centmin.sh menu option 2.
Server Block Structure
A typical vhost configuration file at /usr/local/nginx/conf/conf.d/domain.com.conf:
server {
server_name domain.com www.domain.com;
listen 80;
access_log /home/nginx/domains/domain.com/log/access.log combined buffer=256k flush=5m;
error_log /home/nginx/domains/domain.com/log/error.log;
root /home/nginx/domains/domain.com/public;
# Nginx includes
include /usr/local/nginx/conf/staticfiles.conf;
include /usr/local/nginx/conf/drop.conf;
include /usr/local/nginx/conf/errorpage.conf;
location / {
# ...
}
# PHP-FPM
include /usr/local/nginx/conf/php.conf;
}
Document Root
Centmin Mod uses the following directory structure for each domain:
/home/nginx/domains/domain.com/
public/ # Document root (web files go here)
private/ # Private files (not web-accessible)
log/ # Access and error logs
access.log
error.log
backup/ # Backup directory
Nginx Includes
Centmin Mod uses modular include files to keep configurations organized. These are referenced inside each virtual host config.
| Include File | Purpose |
|---|---|
| staticfiles.conf | Static file caching headers (images, CSS, JS, fonts) |
| drop.conf | Block access to sensitive files (.htaccess, .git, etc.) |
| errorpage.conf | Custom error page definitions (403, 404, 500, 502, etc.) |
| php.conf | PHP-FPM upstream and location blocks |
| 503include-main.conf | Maintenance mode support |
| cloudflare.conf | Cloudflare real IP restoration |
Note about staticfiles.conf
The staticfiles.conf include file has a .html, .htm, .txt location match which may interfere with rewrites of static files, especially if you use WordPress permalinks ending in .html. Remove the .html, .htm, .txt match from staticfiles.conf or choose a permalink format that does not use .html extensions. See issue #35 for details.
The relevant block in staticfiles.conf:
location ~* \.(html|htm|txt)$ {
#add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
access_log off;
expires 1d;
break;
}
Performance Tuning
Centmin Mod ships with production-ready Nginx settings. Below are the key directives you may want to adjust based on your server's workload.
Buffer Sizes
Buffer settings control how Nginx handles request and response data in memory:
client_body_buffer_size 256k;
client_header_buffer_size 64k;
client_max_body_size 50m;
large_client_header_buffers 4 64k;
Timeouts
client_body_timeout 10;
client_header_timeout 10;
send_timeout 60;
Gzip Compression
Gzip compression reduces response sizes and improves page load times. Centmin Mod enables this by default:
gzip on;
gzip_vary on;
gzip_disable "MSIE [1-6]\.";
gzip_proxied any;
gzip_comp_level 5;
gzip_min_length 1024;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json
application/javascript text/xml
application/xml application/xml+rss
text/javascript image/svg+xml;
A gzip_comp_level of 5 provides a good balance between compression ratio and CPU usage. Higher levels yield diminishing returns while increasing CPU overhead.
Nginx Rewrite & App Configs
Nginx does not support Apache mod_rewrite syntax. You need to convert Apache rewrite rules to Nginx's HttpRewriteModule syntax. The official Nginx documentation provides examples for converting Apache rewrites.
Below are links to Nginx configuration examples and rewrite rules for popular web applications:
Can't find what you need? Check the official Nginx forums and the Nginx Wiki.
Testing & Reloading
Always test your Nginx configuration before reloading to avoid downtime from syntax errors.
Test Configuration Syntax
Run the config test command to validate your changes:
nginx -t
A successful test outputs:
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
Reload Nginx
After a successful test, gracefully reload Nginx to apply the new configuration without dropping active connections:
# Reload (graceful - preferred)
service nginx reload
# Or using the Nginx signal directly
nginx -s reload
# Restart (full stop/start - use only when needed)
service nginx restart
Always run nginx -t before service nginx reload. A failed reload due to syntax errors can prevent Nginx from accepting new connections even though existing ones continue to be served.