[GH-ISSUE #835] 反向代理不生效 #6219

Closed
opened 2026-03-01 17:10:25 +03:00 by kerem · 2 comments
Owner

Originally created by @lixingbu-tal on GitHub (Jan 28, 2025).
Original GitHub issue: https://github.com/0xJacky/nginx-ui/issues/835

debian12系统下使用Docker安装nginx-ui最新版镜像 uozi/nginx-ui:latest。在配置反向代理时无论配置什么应用,都会重定向到NGINX-ui的登录界面。

docker-compose.yml配置如下:

services:
  nginx-ui:
    image: uozi/nginx-ui:latest
    restart: always
    stdin_open: true
    tty: true
    network_mode: host
    environment:
      - TZ=Asia/Shanghai
      - NGINX_UI_TERMINAL_START_CMD=bash
      - NGINX_UI_NGINX_LOG_DIR_WHITE_LIST=/var/log/nginx/
    volumes:
      - $PWD/nginx-ui/nginx:/etc/nginx
      - $PWD/nginx-ui/nginx-ui:/etc/nginx-ui
  frps:
    image: snowdreamtech/frps:bookworm
    restart: unless-stopped
    network_mode: host    
    depends_on:
      - nginx-ui
    volumes:
      - $PWD/frp/frps.toml:/etc/frp/frps.toml

nginx-UI 内反向代理配置如下:

map $http_upgrade $connection_upgrade {
    default upgrade;
    '' close;
}
map $remote_addr $proxy_forwarded_elem {
    # IPv4 addresses can be sent as-is
    ~^[0-9.]+$ "for=$remote_addr";
    # IPv6 addresses need to be bracketed and quoted
    ~^[0-9A-Fa-f:.]+$ "for=\"[$remote_addr]\"";
    # Unix domain socket names cannot be represented in RFC 7239 syntax
    default "for=unknown";
}
map $http_forwarded $proxy_add_forwarded {
    # If the incoming Forwarded header is syntactically valid, append to it
    "~^(,[ \\t]*)*([!#$%&'*+.^_`|~0-9A-Za-z-]+=([!#$%&'*+.^_`|~0-9A-Za-z-]+|\"([\\t \\x21\\x23-\\x5B\\x5D-\\x7E\\x80-\\xFF]|\\\\[\\t \\x21-\\x7E\\x80-\\xFF])*\"))?(;([!#$%&'*+.^_`|~0-9A-Za-z-]+=([!#$%&'*+.^_`|~0-9A-Za-z-]+|\"([\\t \\x21\\x23-\\x5B\\x5D-\\x7E\\x80-\\xFF]|\\\\[\\t \\x21-\\x7E\\x80-\\xFF])*\"))?)*([ \\t]*,([ \\t]*([!#$%&'*+.^_`|~0-9A-Za-z-]+=([!#$%&'*+.^_`|~0-9A-Za-z-]+|\"([\\t \\x21\\x23-\\x5B\\x5D-\\x7E\\x80-\\xFF]|\\\\[\\t \\x21-\\x7E\\x80-\\xFF])*\"))?(;([!#$%&'*+.^_`|~0-9A-Za-z-]+=([!#$%&'*+.^_`|~0-9A-Za-z-]+|\"([\\t \\x21\\x23-\\x5B\\x5D-\\x7E\\x80-\\xFF]|\\\\[\\t \\x21-\\x7E\\x80-\\xFF])*\"))?)*)?)*$" "$http_forwarded, $proxy_forwarded_elem";
    # Otherwise, replace it
    default "$proxy_forwarded_elem";
}
server {
    listen 443 ssl;
    listen [::]:443 ssl;
    server_name frps.xxx.com;
    return 308 https://$host$request_uri;
    error_log /var/log/nginx/frps.xxx.com.error.log;
    access_log /var/log/nginx/frps.xxx.com.log;
    ssl_certificate /etc/nginx/ssl/*.xxx.com_2048/fullchain.cer;
    ssl_certificate_key /etc/nginx/ssl/*.xxx.com_2048/private.key;
    if ($host != $server_name) {
        return 404;
    }
    location /.well-known/acme-challenge {
        proxy_set_header Host $host;
        proxy_set_header X-Real_IP $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr:$remote_port;
        proxy_pass http://127.0.0.1:9180;
    }
    location / {
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
        client_max_body_size 1000m;
        proxy_redirect off;
        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_set_header Forwarded $proxy_add_forwarded;
        proxy_pass http://127.0.0.1:7500/;
    }
}

从官方文档中并没有得到解决方案,麻烦请帮我答疑解惑,谢谢各位大佬。

Originally created by @lixingbu-tal on GitHub (Jan 28, 2025). Original GitHub issue: https://github.com/0xJacky/nginx-ui/issues/835 debian12系统下使用Docker安装nginx-ui最新版镜像 uozi/nginx-ui:latest。在配置反向代理时无论配置什么应用,都会重定向到NGINX-ui的登录界面。 ### docker-compose.yml配置如下: ``` services: nginx-ui: image: uozi/nginx-ui:latest restart: always stdin_open: true tty: true network_mode: host environment: - TZ=Asia/Shanghai - NGINX_UI_TERMINAL_START_CMD=bash - NGINX_UI_NGINX_LOG_DIR_WHITE_LIST=/var/log/nginx/ volumes: - $PWD/nginx-ui/nginx:/etc/nginx - $PWD/nginx-ui/nginx-ui:/etc/nginx-ui frps: image: snowdreamtech/frps:bookworm restart: unless-stopped network_mode: host depends_on: - nginx-ui volumes: - $PWD/frp/frps.toml:/etc/frp/frps.toml ``` ### nginx-UI 内反向代理配置如下: ``` map $http_upgrade $connection_upgrade { default upgrade; '' close; } map $remote_addr $proxy_forwarded_elem { # IPv4 addresses can be sent as-is ~^[0-9.]+$ "for=$remote_addr"; # IPv6 addresses need to be bracketed and quoted ~^[0-9A-Fa-f:.]+$ "for=\"[$remote_addr]\""; # Unix domain socket names cannot be represented in RFC 7239 syntax default "for=unknown"; } map $http_forwarded $proxy_add_forwarded { # If the incoming Forwarded header is syntactically valid, append to it "~^(,[ \\t]*)*([!#$%&'*+.^_`|~0-9A-Za-z-]+=([!#$%&'*+.^_`|~0-9A-Za-z-]+|\"([\\t \\x21\\x23-\\x5B\\x5D-\\x7E\\x80-\\xFF]|\\\\[\\t \\x21-\\x7E\\x80-\\xFF])*\"))?(;([!#$%&'*+.^_`|~0-9A-Za-z-]+=([!#$%&'*+.^_`|~0-9A-Za-z-]+|\"([\\t \\x21\\x23-\\x5B\\x5D-\\x7E\\x80-\\xFF]|\\\\[\\t \\x21-\\x7E\\x80-\\xFF])*\"))?)*([ \\t]*,([ \\t]*([!#$%&'*+.^_`|~0-9A-Za-z-]+=([!#$%&'*+.^_`|~0-9A-Za-z-]+|\"([\\t \\x21\\x23-\\x5B\\x5D-\\x7E\\x80-\\xFF]|\\\\[\\t \\x21-\\x7E\\x80-\\xFF])*\"))?(;([!#$%&'*+.^_`|~0-9A-Za-z-]+=([!#$%&'*+.^_`|~0-9A-Za-z-]+|\"([\\t \\x21\\x23-\\x5B\\x5D-\\x7E\\x80-\\xFF]|\\\\[\\t \\x21-\\x7E\\x80-\\xFF])*\"))?)*)?)*$" "$http_forwarded, $proxy_forwarded_elem"; # Otherwise, replace it default "$proxy_forwarded_elem"; } server { listen 443 ssl; listen [::]:443 ssl; server_name frps.xxx.com; return 308 https://$host$request_uri; error_log /var/log/nginx/frps.xxx.com.error.log; access_log /var/log/nginx/frps.xxx.com.log; ssl_certificate /etc/nginx/ssl/*.xxx.com_2048/fullchain.cer; ssl_certificate_key /etc/nginx/ssl/*.xxx.com_2048/private.key; if ($host != $server_name) { return 404; } location /.well-known/acme-challenge { proxy_set_header Host $host; proxy_set_header X-Real_IP $remote_addr; proxy_set_header X-Forwarded-For $remote_addr:$remote_port; proxy_pass http://127.0.0.1:9180; } location / { proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; client_max_body_size 1000m; proxy_redirect off; 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_set_header Forwarded $proxy_add_forwarded; proxy_pass http://127.0.0.1:7500/; } } ``` 从官方文档中并没有得到解决方案,麻烦请帮我答疑解惑,谢谢各位大佬。
kerem 2026-03-01 17:10:25 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@0xJacky commented on GitHub (Jan 28, 2025):

使用了 frp 吗,看起来是 $Host Header 没有携带,你先试试在内网 host 能不能正常用

<!-- gh-comment-id:2618457377 --> @0xJacky commented on GitHub (Jan 28, 2025): 使用了 frp 吗,看起来是 $Host Header 没有携带,你先试试在内网 host 能不能正常用
Author
Owner

@0xJacky commented on GitHub (Jan 30, 2025):

可以的话,发一下 nginx.conf 配置文件的内容

<!-- gh-comment-id:2624734504 --> @0xJacky commented on GitHub (Jan 30, 2025): 可以的话,发一下 nginx.conf 配置文件的内容
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#6219
No description provided.