Can the nginx of dify implement forwarding requests to the web and API through sub paths #4498

Closed
opened 2026-02-21 18:06:47 -05:00 by yindo · 1 comment
Owner

Originally created by @linronghua921122 on GitHub (Jul 8, 2024).

Self Checks

  • 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 (我已阅读并同意 Language Policy).
  • 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

0.6.11

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

When I start the service based on the default nginx configuration file and it can be accessed normally, the default nginx configuration is as follows:
image
But I have a problem that the root path of the domain name has already been used, so I want to add sub paths to all location forwarding paths in the nginx configuration, such as location/diffyserver/, The specific configuration is as follows:
image
After I made the configuration changes and restarted the service, the browser accessed http://ip:port/difyserver Address, page cannot be displayed properly, page displays 404
image
image

✔️ Expected Behavior

I hope the above methods can be supported

Actual Behavior

No response

Originally created by @linronghua921122 on GitHub (Jul 8, 2024). ### Self Checks - [X] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [X] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [X] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [X] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [X] Please do not modify this template :) and fill in all the required fields. ### Dify version 0.6.11 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce When I start the service based on the default nginx configuration file and it can be accessed normally, the default nginx configuration is as follows: ![image](https://github.com/langgenius/dify/assets/86347572/e0e42d6a-5817-4bc5-89c4-050a96bf08b6) But I have a problem that the root path of the domain name has already been used, so I want to add sub paths to all location forwarding paths in the nginx configuration, such as location/diffyserver/, The specific configuration is as follows: ![image](https://github.com/langgenius/dify/assets/86347572/01d1b646-6889-4eb1-a5b8-0a186320fdc0) After I made the configuration changes and restarted the service, the browser accessed http://ip:port/difyserver Address, page cannot be displayed properly, page displays 404 ![image](https://github.com/langgenius/dify/assets/86347572/9796e513-4040-4738-8beb-3b87588b5574) ![image](https://github.com/langgenius/dify/assets/86347572/fa3f9111-c9ba-4aa3-b4ab-0fc8e8a7e5f5) ### ✔️ Expected Behavior I hope the above methods can be supported ### ❌ Actual Behavior _No response_
yindo closed this issue 2026-02-21 18:06:47 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Jul 8, 2024):

To configure Nginx to forward requests to the web and API through sub-paths without encountering 404 errors, you can use the following configuration as a reference:

server {
    listen 80;
    server_name _;

    location /difyserver/console/api {
      proxy_pass http://api:5001/console/api;
      include proxy.conf;
    }

    location /difyserver/api {
      proxy_pass http://api:5001/api;
      include proxy.conf;
    }

    location /difyserver/v1 {
      proxy_pass http://api:5001/v1;
      include proxy.conf;
    }

    location /difyserver/files {
      proxy_pass http://api:5001/files;
      include proxy.conf;
    }

    location /difyserver/ {
      proxy_pass http://web:3000/;
      include proxy.conf;
    }

    # If you want to support HTTPS, please uncomment the code snippet below
    #listen 443 ssl;
    #ssl_certificate ./../ssl/your_cert_file.cer;
    #ssl_certificate_key ./../ssl/your_cert_key.key;
    #ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
    #ssl_prefer_server_ciphers on;
    #ssl_session_cache shared:SSL:10m;
    #ssl_session_timeout 10m;
}

This configuration ensures that:

  • Requests to /difyserver/console/api, /difyserver/api, /difyserver/v1, and /difyserver/files are forwarded to the API service running on http://api:5001.
  • All other requests to /difyserver/ are forwarded to the web service running on http://web:3000.

Make sure that the proxy.conf file includes the necessary proxy settings to handle the forwarding correctly. This setup should prevent 404 errors as long as the paths exist on the respective services [1][2].

Additionally, ensure that the environment variables in your docker-compose.yaml and .env files are set to include the sub-paths. For example:

web:
  image: langgenius/dify-web:0.6.12
  restart: always
  environment:
    CONSOLE_API_URL: 'http://yourdomain.com/difyserver/console'
    APP_API_URL: 'http://yourdomain.com/difyserver/app'

And in your .env file:

CONSOLE_API_URL=http://yourdomain.com/difyserver/console
CONSOLE_WEB_URL=http://yourdomain.com/difyserver/console
APP_WEB_URL=http://yourdomain.com/difyserver/app

These configurations ensure that the Dify web application is aware of the base URLs and any sub-paths configured [3][4][5][6].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Jul 8, 2024): <!-- Answer --> To configure Nginx to forward requests to the web and API through sub-paths without encountering 404 errors, you can use the following configuration as a reference: ```nginx server { listen 80; server_name _; location /difyserver/console/api { proxy_pass http://api:5001/console/api; include proxy.conf; } location /difyserver/api { proxy_pass http://api:5001/api; include proxy.conf; } location /difyserver/v1 { proxy_pass http://api:5001/v1; include proxy.conf; } location /difyserver/files { proxy_pass http://api:5001/files; include proxy.conf; } location /difyserver/ { proxy_pass http://web:3000/; include proxy.conf; } # If you want to support HTTPS, please uncomment the code snippet below #listen 443 ssl; #ssl_certificate ./../ssl/your_cert_file.cer; #ssl_certificate_key ./../ssl/your_cert_key.key; #ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3; #ssl_prefer_server_ciphers on; #ssl_session_cache shared:SSL:10m; #ssl_session_timeout 10m; } ``` This configuration ensures that: - Requests to `/difyserver/console/api`, `/difyserver/api`, `/difyserver/v1`, and `/difyserver/files` are forwarded to the API service running on `http://api:5001`. - All other requests to `/difyserver/` are forwarded to the web service running on `http://web:3000`. Make sure that the `proxy.conf` file includes the necessary proxy settings to handle the forwarding correctly. This setup should prevent 404 errors as long as the paths exist on the respective services <sup>[[1]](https://github.com/langgenius/dify/blob/main/docker/nginx/conf.d/default.conf.template)</sup><sup>[[2]](https://github.com/langgenius/dify/blob/main/docker-legacy/nginx/conf.d/default.conf)</sup>. Additionally, ensure that the environment variables in your `docker-compose.yaml` and `.env` files are set to include the sub-paths. For example: ```yaml web: image: langgenius/dify-web:0.6.12 restart: always environment: CONSOLE_API_URL: 'http://yourdomain.com/difyserver/console' APP_API_URL: 'http://yourdomain.com/difyserver/app' ``` And in your `.env` file: ```env CONSOLE_API_URL=http://yourdomain.com/difyserver/console CONSOLE_WEB_URL=http://yourdomain.com/difyserver/console APP_WEB_URL=http://yourdomain.com/difyserver/app ``` These configurations ensure that the Dify web application is aware of the base URLs and any sub-paths configured <sup>[[3]](https://github.com/langgenius/dify/blob/main/docker-legacy/docker-compose.yaml)</sup><sup>[[4]](https://github.com/langgenius/dify/blob/main/api/app.py)</sup><sup>[[5]](https://github.com/langgenius/dify/blob/main/api/.env.example)</sup><sup>[[6]](https://github.com/langgenius/dify/blob/main/api/configs/feature/__init__.py)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#4498