Skip to content

Open Web App link drops external port when APP_WEB_URL is empty (reproduced on 1.17.1) #43877

Open

Description

@siqiniao

Self Checks

  • I have read the Contributing Guide and Language Policy.
  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report, otherwise it will be closed.
  • 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

1.17.1 (langgenius/dify-api:1.17.1, langgenius/dify-web:1.17.1)

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

Related: #37780, which was closed as not planned. This report provides a reproduction on 1.17.1 and a verified proxy-level workaround.

Environment: macOS, Docker Desktop, bundled Nginx reverse proxy, Chrome. Dify is exposed on host port 8081; APP_WEB_URL is empty. App identifiers below are placeholders.

  1. Deploy Dify with the bundled Nginx proxy and expose its HTTP listener on a non-standard host port, e.g. EXPOSE_NGINX_PORT=8081.
  2. Leave APP_WEB_URL unset/empty.
  3. Access the console at http://localhost:8081.
  4. Create and publish a chat application.
  5. Open the Publish menu and click Open Web App.
  6. Observe that the generated link omits :8081.

✔️ Expected Behavior

The generated link preserves the browser-facing host and port:

http://localhost:8081/chat/<app-code>

Opening it should load the published application.

❌ Actual Behavior

The generated link is:

http://localhost/chat/<app-code>

It targets port 80 rather than Dify's exposed port 8081. In this environment another local HTTP listener answers with 404. On a host without a port-80 listener, the symptom may instead be a connection failure.

Verified before the workaround:

  • Generated console link omitted :8081.
  • The port-80 URL returned HTTP 404.
  • The same application path at localhost:8081 returned HTTP 200.

Root cause observed in source/configuration

docker/nginx/proxy.conf.template contains:

proxy_set_header Host $host;
proxy_set_header X-Forwarded-Port $server_port;

Nginx $host omits the request port. $server_port represents the internal listener port, which need not equal the externally mapped Docker port.

The application URL fallback uses:

dify_config.APP_WEB_URL or request.url_root.rstrip("/")

This appears in api/models/model.py (Site.app_base_url) and api/controllers/console/app/app.py. With APP_WEB_URL empty, the forwarded request host therefore loses the external port.

Verified local workaround

Changed the Host forwarding directive in both the active Nginx configuration and its persistent template:

-proxy_set_header Host $host;
+proxy_set_header Host $http_host;

Then ran nginx -t successfully, reloaded Nginx, and refreshed the console.

After the change:

  • The Open Web App link included localhost:8081.
  • Clicking the actual link opened the published chat application.
  • The application title, welcome message, existing conversation, and chat input loaded successfully. Verification went beyond the HTTP 200 response; no new model inference was run for this check.

Explicitly setting APP_WEB_URL=http://localhost:8081 is another configuration workaround, but was not applied in this reproduction.

Please consider preserving the external authority (including non-standard port) in the bundled proxy/fallback URL generation, or documenting the required explicit URL setting alongside custom port configuration. The $http_host change above is a locally verified workaround, not a claim that it is sufficient for every reverse-proxy topology.

Activity

  1. dosubot commented on Oct 11, 2026

    @dosubot

    Hi @siqiniao! I'm Dosu and I'm helping the Dify team.

    Your root cause analysis holds. The bundled template still sets Host $host and X-Forwarded-Port $server_port. When APP_WEB_URL is unset, the Site.app_base_url fallback uses the incoming request root [1], and $host drops the port.

    PR #37893, "fix: preserve web app URL port through nginx", makes your $http_host change. It forwards Host as $http_host and adds a template regression test. I couldn't confirm whether it has merged, and the template in the checkout I read still has $host.

    Until the template changes, two other options can restore the port:

    • Set APP_WEB_URL explicitly, e.g. APP_WEB_URL=http://localhost:8081. This is the most reliable option.
    • Set RESPECT_XFORWARD_HEADERS_ENABLED=true. This wraps the app in Werkzeug's ProxyFix, which rebuilds the host from X-Forwarded-Port [2]. The template already sends that header, but $server_port is the nginx listener port, so with a Docker mapping like 8081:80 it would carry the internal port. I haven't verified whether this gives you :8081 in your setup.

    #37780 reported the same behaviour for generated MCP server URLs [2], so a fix in the nginx template would cover both.

    To reply, just mention @dosu.


    Docs are dead. Just use Dosu.

    Leave Feedback Ask Dosu about dify

  2. Stream29 commented on Oct 12, 2026

    @Stream29
    Contributor

    Reproduced on 1.17.1 with APP_WEB_URL empty: the Open Web App link drops the external port. Changing nginx Host forwarding from $host to $http_host preserves it.

    Before:
    Before: external port dropped

    After:
    After: external port preserved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    review: lowghfind author score; see https://ghfind.com

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions