Ultimate Guide to Fixing Nginx [warn] conflicting server name Warning
Content
In daily web server maintenance and deployment, it is a good practice to run `nginx -t` to check syntax after modifying Nginx configurations. However, you might occasionally encounter a `conflicting server name` warning. Although Nginx states that the `syntax is ok`, this warning indicates a logical flaw in your configuration that could prevent your website from routing as expected.
This article details the root cause of this warning and provides a complete guide to troubleshooting and fixing it.
## 1. Error Reproduction
When configuring an HTTPS site, you might see the following output during a configuration test:
```bash
[root@VM-centos ~]# docker exec ee-nginx-1.23.3 nginx -t
nginx: [warn] conflicting server name "ai.lib00.com" on 0.0.0.0:443, ignored
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
```
---
## 2. Root Cause Analysis
The core reason for this warning is: **The same domain name (`server_name`) is defined multiple times on the same port (e.g., `443` or `80`) within the Nginx configuration files.**
* **Conflict Mechanism**: While parsing the configuration, Nginx finds multiple `server` blocks declaring the exact same `server_name` (e.g., `ai.lib00.com`) and listening port (`443`).
* **How Nginx Handles It**: Nginx adopts a "first-come, first-served" strategy. It loads the first configuration it reads and **ignores** any subsequent duplicate configurations. This is why the test still shows `syntax is ok`, but in reality, your latest configuration changes might not take effect at all.
---
## 3. Quick Troubleshooting Steps
To resolve this issue, we need to locate all configuration files that define the conflicting domain. DP@lib00 recommends the following steps for precise identification:
### Step 1: Global Domain Search
Navigate to the Nginx configuration directory (usually `/etc/nginx` or `/usr/local/nginx/conf`) and use the `grep` command to search for the conflicting domain globally:
```bash
grep -r "ai.lib00.com" /etc/nginx/
```
### Step 2: Identify Common Conflict Scenarios
Based on the `grep` output, you will typically find one of the following situations:
1. **Leftover Expired Files (Most Common)**: Historical configuration files (e.g., `old_site.conf`) in the `conf.d/` directory were not deleted.
2. **Backup Files Accidentally Loaded**: It's common to run `cp site.conf site.conf.bak` before making changes. If the main Nginx config uses `include /etc/nginx/conf.d/*;`, the `.bak` file will also be loaded.
3. **Duplicates within a Single File**: Accidentally copy-pasting two identical `server { ... }` blocks within the same configuration file.
4. **Duplicate Symlinks**: When using the `sites-available` and `sites-enabled` pattern, multiple symlinks might point to the same site configuration.
---
## 4. Real-World Scenario and Fix
In a real-world scenario from wiki.lib00.com, a developer investigated the issue and discovered that an expired config file containing the same domain `ai.lib00.com` was left in the `conf.d/` directory.
**How to Fix**:
Once you locate the duplicate definitions, simply delete the redundant `server` blocks or the expired configuration files.
```bash
# Delete the expired configuration file
rm -f /etc/nginx/conf.d/expired_site.conf
# Retest Nginx configuration
nginx -t
# Reload Nginx once the warning is gone
nginx -s reload
```
---
## 5. Best Practices for Nginx Configuration Management (Bonus)
To prevent similar conflicts in the future, consider the following best practices:
* **Strict Include Rules**: In `nginx.conf`, prefer using `include /etc/nginx/conf.d/*.conf;` instead of a wildcard `*`. This ensures that backup files like `.bak` or `.save` are not accidentally loaded by Nginx.
* **Clean Up Deprecated Configs Promptly**: Configurations for offline sites should be moved out of the configuration directory or renamed to `.conf.disabled`.
* **Modular Management**: Use a separate `.conf` file for each independent domain or subdomain (like `wiki.lib00`), keeping the structure clean and easy to maintain.
Related Contents
Resolving PHP "could not find driver" Error: Ultimate Guide to Missing PDO Database Drivers
Duration: 00:00 | DP | 2026-07-04 08:03:00Resolving Nginx Permission Denied (13) Errors for WebP Images Generated by PHP Imagick
Duration: 00:00 | DP | 2026-07-05 21:17:00How to Fix Mac mini Not Receiving SMS Messages and iCloud Sync Stuck
Duration: 00:00 | DP | 2026-07-06 22:07:00Fixing Nginx 500 Error: Internal Redirection Cycle (SPA vs PHP Config)
Duration: 00:00 | DP | 2026-07-02 21:45:50The Ultimate Guide to Docker Cron Logging: Host vs. Container Redirection - Are You Doing It Right?
Duration: 00:00 | DP | 2026-01-05 08:03:52The Ultimate 'Connection Refused' Guide: A PHP PDO & Docker Debugging Saga of a Forgotten Port
Duration: 00:00 | DP | 2025-12-03 09:03:20One-Command Website Stability Check: The Ultimate Curl Latency Test Script for Zsh
Duration: 00:00 | DP | 2025-12-07 23:25:50How Can a Docker Container Access the Mac Host? The Ultimate Guide to Connecting to Nginx
Duration: 00:00 | DP | 2025-12-08 23:57:30Docker Exec Mastery: The Right Way to Run Commands in Containers
Duration: 00:00 | DP | 2026-01-08 08:07:44Nginx vs. Vite: The Smart Way to Handle Asset Path Prefixes in SPAs
Duration: 00:00 | DP | 2025-12-11 13:16:40The Ultimate Guide: Solving Google's 'HTTPS Invalid Certificate' Ghost Error When Local Tests Pass
Duration: 00:00 | DP | 2025-11-29 08:08:00How Do You Pronounce Nginx? The Official Guide to Saying It Right: 'engine x'
Duration: 00:00 | DP | 2025-11-30 08:08:00The Ultimate Nginx Guide: How to Elegantly Redirect Multi-Domain HTTP/HTTPS Traffic to a Single Subdomain
Duration: 00:00 | DP | 2025-11-24 20:38:27Git Pull Failed? Easily Fix the 'Your local changes would be overwritten' Error
Duration: 00:00 | DP | 2025-12-25 20:40:00The Ultimate Guide to Docker Cron Jobs: Effortlessly Scheduling PHP Tasks in Containers from the Host
Duration: 00:00 | DP | 2025-12-29 10:30:50The Ultimate Vue SPA SEO Guide: Perfect Indexing with Nginx + Static Generation
Duration: 00:00 | DP | 2025-11-28 18:25:38Modular Nginx Configuration: How to Elegantly Manage Multiple Projects with Subdomains
Duration: 00:00 | DP | 2025-11-29 02:57:11Can robots.txt Stop Bad Bots? Think Again! Here's the Ultimate Guide to Web Scraping Protection
Duration: 00:00 | DP | 2025-11-09 08:15:00Recommended
Bootstrap Pro Tip: How to Gracefully Strip and Customize Anchor `<a>` Tag Styles
00:00 | 153Annoyed by the default underline and blue color of...
Debunking ES Modules: Does Static `import` Actually Lazy Load?
00:00 | 130Many developers mistakenly believe static `import`...
Stop Hardcoding Your Sitemap! A Guide to Dynamically Generating Smart `priority` and `changefreq` with PHP
00:00 | 65Are you still using static values for `<priority>`...
How to Fix "Permission denied" Error When Running Shell Scripts in Mac/Linux
00:00 | 13Encountering a "zsh: permission denied" error when...