Skip to content

當server_name設置與本機相同ip時,nginx-ui會出錯 #432

Answered by 0xJacky
ChanKaHou asked this question in Q&A
Discussion options

You must be logged in to vote

已經可以復現,這個問題是由於 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…

Replies: 8 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by ChanKaHou
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #430 on July 04, 2024 11:45.