You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

将域名映射到NGINX子目录且保留浏览器域名的配置求助

解决方案:NGINX多域名访问配置调整

1. 修改默认Server配置

编辑/etc/nginx/sites-available/default,将泛域名匹配改为明确指向mydomain,避免干扰其他域名的请求处理:

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

    root /var/www/html;

    # 仅匹配mydomain的请求
    server_name mydomain;

    include /etc/nginx/sites-available/subdirs/*;
}

2. 调整WebBoss子目录配置

编辑/etc/nginx/sites-available/subdirs/webboss,修改根路径跳转规则为仅针对mydomain生效,同时为boss-test.com.nl添加根路径代理逻辑:

# 保留原有/webboss路径配置,确保mydomain/webboss正常访问
location /webboss {
    include proxy_params;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header SCRIPT_NAME /webboss;
    proxy_redirect off;
    proxy_connect_timeout 1200s;
    proxy_send_timeout 1200s;
    proxy_read_timeout 1200s;
    fastcgi_send_timeout 1200s;
    fastcgi_read_timeout 1200s;
    if (!-f $request_filename) {
        proxy_pass http://unix:/srv/webboss/run/webboss.sock;
        break;
    }
}

# 修改根路径处理逻辑:分域名处理
location / {
    # 仅当访问mydomain根目录时,跳转至mydomain/webboss
    if ($host = mydomain) {
        return 301 http://$host/webboss;
    }

    # 处理boss-test.com.nl等其他域名的根路径请求,直接代理WebBoss服务
    include proxy_params;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    # 根路径访问无需设置SCRIPT_NAME前缀
    proxy_set_header SCRIPT_NAME "";
    proxy_redirect off;
    proxy_connect_timeout 1200s;
    proxy_send_timeout 1200s;
    proxy_read_timeout 1200s;
    fastcgi_send_timeout 1200s;
    fastcgi_read_timeout 1200s;
    if (!-f $request_filename) {
        proxy_pass http://unix:/srv/webboss/run/webboss.sock;
        break;
    }
}

3. 验证配置并重启NGINX

执行命令验证配置语法正确性:

sudo nginx -t

若提示test is successful,重启NGINX使配置生效:

sudo systemctl restart nginx

效果说明

  • 访问http://mydomain会自动跳转至http://mydomain/webboss,地址栏保留mydomain域名
  • 访问http://boss-test.com.nl或http://boss-test.com.nl/webboss均直接加载WebBoss内容,地址栏保持boss-test.com.nl域名不变
  • 原有的http://mydomain/webboss访问路径正常工作

内容的提问来源于stack exchange,提问作者Ruben

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.13 04:05:41