[GH-ISSUE #430] 當server_name設置與本機相同ip時,nginx-ui會出錯 #3351

Closed
opened 2026-02-28 11:55:42 +03:00 by kerem · 8 comments
Owner

Originally created by @chankahou0968 on GitHub (Jul 3, 2024).
Original GitHub issue: https://github.com/0xJacky/nginx-ui/issues/430

Describe the bug
server_name 設置其它 doaminname 或 ip都沒事,只是設置為本機ip時便會出錯

Info (please complete the following information):

  • 使用docker image
  • 以下是portainer-stack部署,設置環境變量${NAME}和${NETWORK}後便可以直接用

version: '3.8'
services:
app:
image: 'uozi/nginx-ui:latest'
container_name: ${NAME}
hostname: ${NAME}
restart: unless-stopped
ports:
- '80:80'
- '443:443'
volumes:
- /mnt/user/appdata/nginx:/etc/nginx
- /mnt/user/appdata/nginx-ui:/etc/nginx-ui
- /var/www:/var/www
environment:
- TZ=Asia/Macau
network_mode: ${NETWORK}

Originally created by @chankahou0968 on GitHub (Jul 3, 2024). Original GitHub issue: https://github.com/0xJacky/nginx-ui/issues/430 **Describe the bug** server_name 設置其它 doaminname 或 ip都沒事,只是設置為本機ip時便會出錯 **Info (please complete the following information):** - 使用docker image - 以下是portainer-stack部署,設置環境變量${NAME}和${NETWORK}後便可以直接用 version: '3.8' services: app: image: 'uozi/nginx-ui:latest' container_name: ${NAME} hostname: ${NAME} restart: unless-stopped ports: - '80:80' - '443:443' volumes: - /mnt/user/appdata/nginx:/etc/nginx - /mnt/user/appdata/nginx-ui:/etc/nginx-ui - /var/www:/var/www environment: - TZ=Asia/Macau network_mode: ${NETWORK}
kerem closed this issue 2026-02-28 11:55:42 +03:00
Author
Owner

@0xJacky commented on GitHub (Jul 4, 2024):

你好,請問是出現什麼錯誤?

<!-- gh-comment-id:2208674395 --> @0xJacky commented on GitHub (Jul 4, 2024): 你好,請問是出現什麼錯誤?
Author
Owner

@chankahou0968 commented on GitHub (Jul 4, 2024):

是整個nginx-ui都崩潰了:

詳情是,我的本機ip是202.175.25.224,新增location時要求輸入server_name,
由於沒有domainname,所以我便輸入202.175.25.224,
之後按確定後便系統崩了,browser刷新後連nginx-ui都開不出來了。

解決辦法是進入uozi/nginx-ui:latest的container內,把/etc/nginx/sites-enabled與/etc/nginx/sites-avaible內有文件删掉,
再nginx -s reload後便回覆正常。

希望有解決辦法,謝謝。

<!-- gh-comment-id:2208697182 --> @chankahou0968 commented on GitHub (Jul 4, 2024): 是整個nginx-ui都崩潰了: 詳情是,我的本機ip是202.175.25.224,新增location時要求輸入server_name, 由於沒有domainname,所以我便輸入202.175.25.224, 之後按確定後便系統崩了,browser刷新後連nginx-ui都開不出來了。 解決辦法是進入uozi/nginx-ui:latest的container內,把/etc/nginx/sites-enabled與/etc/nginx/sites-avaible內有文件删掉, 再nginx -s reload後便回覆正常。 希望有解決辦法,謝謝。
Author
Owner

@0xJacky commented on GitHub (Jul 4, 2024):

新增 location 的時候,並不會要求輸入 server_name,可否提供一下截圖?

<!-- gh-comment-id:2208715192 --> @0xJacky commented on GitHub (Jul 4, 2024): 新增 location 的時候,並不會要求輸入 server_name,可否提供一下截圖?
Author
Owner

@0xJacky commented on GitHub (Jul 4, 2024):

我在測試環境中無法復現這個問題

<!-- gh-comment-id:2208716454 --> @0xJacky commented on GitHub (Jul 4, 2024): 我在測試環境中無法復現這個問題
Author
Owner

@0xJacky commented on GitHub (Jul 4, 2024):

麻煩提供一下 /etc/nginx/sites-avaible 內引發問題的配置文件的內容

<!-- gh-comment-id:2208724952 --> @0xJacky commented on GitHub (Jul 4, 2024): 麻煩提供一下 /etc/nginx/sites-avaible 內引發問題的配置文件的內容
Author
Owner

@chankahou0968 commented on GitHub (Jul 4, 2024):

圖1是剛啓動的界面;
圖2是新增網站時的界面,我在server_name輸入202.175.25.224 (本機ip),按下一步後,
圖3是界面都還算正常,我甚麼都沒動,但這時已經崩了,因為再按下一步都沒有反應,
圖4是nginx-ui已出錯
圖5是按下刷新後,nginx-ui已刷不出來了

1 2 3 4 5
<!-- gh-comment-id:2208735609 --> @chankahou0968 commented on GitHub (Jul 4, 2024): 圖1是剛啓動的界面; 圖2是新增網站時的界面,我在server_name輸入202.175.25.224 (本機ip),按下一步後, 圖3是界面都還算正常,我甚麼都沒動,但這時已經崩了,因為再按下一步都沒有反應, 圖4是nginx-ui已出錯 圖5是按下刷新後,nginx-ui已刷不出來了 <img width="1920" alt="1" src="https://github.com/0xJacky/nginx-ui/assets/38522240/64126784-f101-4990-a5ac-24abea035d8e"> <img width="1920" alt="2" src="https://github.com/0xJacky/nginx-ui/assets/38522240/90a37ba2-25d5-49d4-83fd-5a790600439e"> <img width="1920" alt="3" src="https://github.com/0xJacky/nginx-ui/assets/38522240/2fabdb76-4131-4abb-b1de-bfc31b06d00c"> <img width="1920" alt="4" src="https://github.com/0xJacky/nginx-ui/assets/38522240/252c5bcc-a99e-492c-a51a-73e90dad5777"> <img width="1920" alt="5" src="https://github.com/0xJacky/nginx-ui/assets/38522240/08d3c223-19d4-4e5c-9a89-d087b2e01e31">
Author
Owner

@chankahou0968 commented on GitHub (Jul 4, 2024):

我是用另一台pc(非202.175.25.224)用browser login到nginx-ui進行上述操作的

還有,只要圖2輸入別的內容時,是不會報錯的

謝謝。

<!-- gh-comment-id:2208738421 --> @chankahou0968 commented on GitHub (Jul 4, 2024): 我是用另一台pc(非202.175.25.224)用browser login到nginx-ui進行上述操作的 還有,只要圖2輸入別的內容時,是不會報錯的 謝謝。
Author
Owner

@0xJacky commented on GitHub (Jul 4, 2024):

已經可以復現,這個問題是由於 nginx 配置衝突造成的,與 nginx-ui 無關。

因為我們在 docker 容器中的 /etc/nginx/conf.d/nginx-ui.conf 文件內配置了反向代理 server_name localhost;,因此容器內的 Nginx 會監聽 localhost:80,然後通過 docker 的端口映射,我們可以將 外部ip:80 映射到容器內的 80 端口,因此正常情況下反向代理是可以正常工作的。

但是如果你新建了一個 server_name 為伺服器的外部 ip,那麼容器內的 nginx 也會監聽這個 ip:80,因此如果你用這個ip去訪問,則他不會走我們配置在 localhost:80 的反向代理規則,因此表現出來的問題就是 404。

由於您目前暫時沒有域名,為了不影響正常業務,我建議:
方案一:
將映射容器內的 nginx-ui 端口(通常情況下是 9000)到服務器上 9000 端口(或者其他),此時在 browser 中可以使用 ip:9000 正常訪問,80 端口及 443 端口可以用於配置其他業務

方案二:
在新配置文件中配置反向代理規則,在 browser 中可以使用 ip/nginx-ui 正常訪問

map $http_upgrade $connection_upgrade {
    default upgrade;
    ''      close;
}

server {
    listen          80;
    listen          [::]:80;

    server_name     <your_server_name>;
     location /nginx-ui/ {
        proxy_set_header    Host                $host;
        proxy_set_header    X-Real-IP           $remote_addr;
        proxy_set_header    X-Forwarded-For     $proxy_add_x_forwarded_for;
        proxy_set_header    X-Forwarded-Proto   $scheme;
        proxy_http_version  1.1;
        proxy_set_header    Upgrade             $http_upgrade;
        proxy_set_header    Connection          $connection_upgrade;
        proxy_pass          http://127.0.0.1:9000/;
    }
}

<!-- gh-comment-id:2208764820 --> @0xJacky commented on GitHub (Jul 4, 2024): 已經可以復現,這個問題是由於 nginx 配置衝突造成的,與 nginx-ui 無關。 因為我們在 docker 容器中的 /etc/nginx/conf.d/nginx-ui.conf 文件內配置了反向代理 `server_name localhost;`,因此容器內的 Nginx 會監聽 localhost:80,然後通過 docker 的端口映射,我們可以將 外部ip:80 映射到容器內的 80 端口,因此正常情況下反向代理是可以正常工作的。 但是如果你新建了一個 server_name 為伺服器的外部 ip,那麼容器內的 nginx 也會監聽這個 ip:80,因此如果你用這個ip去訪問,則他不會走我們配置在 localhost:80 的反向代理規則,因此表現出來的問題就是 404。 由於您目前暫時沒有域名,為了不影響正常業務,我建議: 方案一: 將映射容器內的 nginx-ui 端口(通常情況下是 9000)到服務器上 9000 端口(或者其他),此時在 browser 中可以使用 ip:9000 正常訪問,80 端口及 443 端口可以用於配置其他業務 方案二: 在新配置文件中配置反向代理規則,在 browser 中可以使用 ip/nginx-ui 正常訪問 ``` map $http_upgrade $connection_upgrade { default upgrade; '' close; } server { listen 80; listen [::]:80; server_name <your_server_name>; location /nginx-ui/ { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; proxy_pass http://127.0.0.1:9000/; } } ```
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#3351
No description provided.