[GH-ISSUE #1510] Stream重命名时,被同步的节点不能删除旧stream #7955

Closed
opened 2026-03-12 23:25:32 +03:00 by kerem · 2 comments
Owner

Originally created by @FourLeafTec on GitHub (Jan 3, 2026).
Original GitHub issue: https://github.com/0xJacky/nginx-ui/issues/1510

Stream配置[S1]由主节点向节点A同步

在主节点重命名[S1]为[S2],节点A不能同步重命名,会变成[S1],[S2]共存,这时Stream里的upstream命名就会冲突

另外我这里还有个问题不知道是不是和这个问题有关
主节点第一次向节点A同步[S1]时,节点A也会报[emerg] duplicate upstream "s1_upstream"

通过grep -r "upstream s1_upstream" /etc/nginx/ 也查不到第二个这个upstream

[S1]配置为

map $ssl_preread_server_name $backend_name {
    ~^S1_.*$ s1_upstream;
    default http_backend;
}
upstream s1_upstream {
    server s1-server:55782;
}
upstream http_backend {
    server 127.0.0.1:8443;
}
server {
    listen 443;
    listen [::]:443;
    ssl_preread on;
    proxy_pass $backend_name;
    proxy_protocol on;
    proxy_timeout 20s;
}

找到原因了,但不知道是哪一步操作引起的,nginx.conf变成了下面这样,stream和http的配置都被修改成了include两遍

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /run/nginx.pid;
events {
    worker_connections 1024;
}
http {
    include /etc/nginx/mime.types;
    default_type application/octet-stream;
    log_format main '$remote_addr - $remote_user [$time_local] "$request" '
        '$status $body_bytes_sent "$http_referer" '
        '"$http_user_agent" "$http_x_forwarded_for"';
    access_log /var/log/nginx/access.log main;
    sendfile on;
    #tcp_nopush     on;
    keepalive_timeout 65;
    #gzip  on;
    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
    include /etc/nginx/sites-enabled/*;
}
stream {
    include /etc/nginx/streams-enabled/*;
    include /etc/nginx/streams-enabled/*;
}
Originally created by @FourLeafTec on GitHub (Jan 3, 2026). Original GitHub issue: https://github.com/0xJacky/nginx-ui/issues/1510 Stream配置[S1]由主节点向节点A同步 在主节点重命名[S1]为[S2],节点A不能同步重命名,会变成[S1],[S2]共存,这时Stream里的upstream命名就会冲突 另外我这里还有个问题不知道是不是和这个问题有关 主节点第一次向节点A同步[S1]时,节点A也会报[emerg] duplicate upstream "s1_upstream" 通过grep -r "upstream s1_upstream" /etc/nginx/ 也查不到第二个这个upstream [S1]配置为 ``` map $ssl_preread_server_name $backend_name { ~^S1_.*$ s1_upstream; default http_backend; } upstream s1_upstream { server s1-server:55782; } upstream http_backend { server 127.0.0.1:8443; } server { listen 443; listen [::]:443; ssl_preread on; proxy_pass $backend_name; proxy_protocol on; proxy_timeout 20s; } ``` 找到原因了,但不知道是哪一步操作引起的,nginx.conf变成了下面这样,stream和http的配置都被修改成了include两遍 ``` user nginx; worker_processes auto; error_log /var/log/nginx/error.log notice; pid /run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; #gzip on; include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; include /etc/nginx/sites-enabled/*; } stream { include /etc/nginx/streams-enabled/*; include /etc/nginx/streams-enabled/*; } ```
kerem 2026-03-12 23:25:32 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@0xJacky commented on GitHub (Feb 7, 2026):

@cursoragent fix it

<!-- gh-comment-id:3864523862 --> @0xJacky commented on GitHub (Feb 7, 2026): @cursoragent fix it
Author
Owner

@cursor[bot] commented on GitHub (Feb 7, 2026):

I've fixed the issue with duplicate include directives in nginx.conf. Here's a summary of the changes:

Problem: The FixNginxConfIncludeSites, FixNginxConfIncludeStreams, and FixNginxConfIncludeConfD functions in internal/self_check/nginx_conf.go were appending include directives without checking if they already existed. This caused duplicate includes like:

include /etc/nginx/sites-enabled/*;
include /etc/nginx/sites-enabled/*;

Solution: Added checks in each Fix function to verify if the include directive already exists before adding a new one:

  • FixNginxConfIncludeSites now checks for existing sites-enabled includes
  • FixNginxConfIncludeStreams now checks for existing streams-enabled includes
  • FixNginxConfIncludeConfD now checks for existing conf.d includes

If the include already exists, the functions return nil without modifying the file.

Testing: Added a new test TestFixNginxConfNoDuplicateIncludes that:

  • Starts with a config file that already has all includes
  • Calls each fix function 3 times
  • Verifies that each include directive appears exactly once in the final file

View PR

Open in Cursor Open in Web

<!-- gh-comment-id:3864523989 --> @cursor[bot] commented on GitHub (Feb 7, 2026): I've fixed the issue with duplicate include directives in nginx.conf. Here's a summary of the changes: **Problem:** The `FixNginxConfIncludeSites`, `FixNginxConfIncludeStreams`, and `FixNginxConfIncludeConfD` functions in `internal/self_check/nginx_conf.go` were appending include directives without checking if they already existed. This caused duplicate includes like: ```nginx include /etc/nginx/sites-enabled/*; include /etc/nginx/sites-enabled/*; ``` **Solution:** Added checks in each Fix function to verify if the include directive already exists before adding a new one: - `FixNginxConfIncludeSites` now checks for existing `sites-enabled` includes - `FixNginxConfIncludeStreams` now checks for existing `streams-enabled` includes - `FixNginxConfIncludeConfD` now checks for existing `conf.d` includes If the include already exists, the functions return `nil` without modifying the file. **Testing:** Added a new test `TestFixNginxConfNoDuplicateIncludes` that: - Starts with a config file that already has all includes - Calls each fix function 3 times - Verifies that each include directive appears exactly once in the final file <p><a href="https://github.com/0xJacky/nginx-ui/pull/1550"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/view-pr-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/view-pr-light.png"><img alt="View PR" width="86" height="28" src="https://cursor.com/assets/images/view-pr-light.png"></picture></a></p> <p><a href="https://cursor.com/background-agent?bcId=bc-1acdba5c-3a44-40b9-a740-6331ef7daf7a"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/open-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/open-in-cursor-light.png"><img alt="Open in Cursor" width="131" height="28" src="https://cursor.com/assets/images/open-in-cursor-dark.png"></picture></a>&nbsp;<a href="https://cursor.com/agents?id=bc-1acdba5c-3a44-40b9-a740-6331ef7daf7a"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/open-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/open-in-web-light.png"><img alt="Open in Web" width="114" height="28" src="https://cursor.com/assets/images/open-in-web-dark.png"></picture></a></p>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/nginx-ui#7955
No description provided.