How to properly change web server port #14968

Closed
opened 2026-02-21 19:19:34 -05:00 by yindo · 3 comments
Owner

Originally created by @KuiliangL on GitHub (Jun 27, 2025).

Self Checks

  • 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).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

1. Is this request related to a challenge you're experiencing? Tell me about your story.

Hi,I'm trying to change the web server port from the default 3000 to 4000 in my Dify installation(version v1.4.1).Because I have a dify. Because I have a Docker version of the Dify application, for some reasons, I am installing Dify from the source code. To avoid conflicts, I want to change the port configuration of Dify. I changed the API port, but I found that I couldn't change the WEB port. This led to me being stuck on the install page when accessing it. I don't know if it's due to a port conflict. I want to change it, but I failed. I've tried the following approaches but the server still runs on port 3000. I Attempt to start with the command: pnpm start -- -p 4000, but it does not work. The API and Worker of the application can start normally and I have modified .env and .env.local file. I changed the default API port from 5001 to 8756 and started API service with 8756 port. I'm not sure if it's a port conflict, but can you tell me how to modify the WEB port? Thanks

2. Additional context or comments

No response

3. Can you help us with this feature?

  • I am interested in contributing to this feature.
Originally created by @KuiliangL on GitHub (Jun 27, 2025). ### Self Checks - [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] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [x] Please do not modify this template :) and fill in all the required fields. ### 1. Is this request related to a challenge you're experiencing? Tell me about your story. Hi,I'm trying to change the web server port from the default 3000 to 4000 in my Dify installation(version v1.4.1).Because I have a dify. Because I have a Docker version of the Dify application, for some reasons, I am installing Dify from the source code. To avoid conflicts, I want to change the port configuration of Dify. I changed the API port, but I found that I couldn't change the WEB port. This led to me being stuck on the install page when accessing it. I don't know if it's due to a port conflict. I want to change it, but I failed. I've tried the following approaches but the server still runs on port 3000. I Attempt to start with the command: **_pnpm start -- -p 4000_**, but it does not work. The API and Worker of the application can start normally and I have modified .env and .env.local file. I changed the default API port from 5001 to 8756 and started API service with 8756 port. I'm not sure if it's a port conflict, but can you tell me how to modify the WEB port? Thanks ### 2. Additional context or comments _No response_ ### 3. Can you help us with this feature? - [ ] I am interested in contributing to this feature.
yindo added the 🙋‍♂️ question label 2026-02-21 19:19:34 -05:00
yindo closed this issue 2026-02-21 19:19:34 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Jun 27, 2025):

Hi @KuiliangL! I'm Dosu and I’m helping the dify team.

To change the Dify web frontend port when running from source, set the port using the environment variable PORT or the --port argument. The .env and .env.local files do not affect the web server port.

The recommended way is:

pnpm run start --port=4000 --host=0.0.0.0

or set the environment variable:

PORT=4000 pnpm run start

This works because the Next.js server (used by Dify's frontend) reads the PORT variable or --port argument at startup web/README.md web/next.config.js.

Your previous command pnpm start -- -p 4000 does not work because the correct flag is --port=4000, not -p 4000.

If you still get stuck on the install page, double-check that no other process is using port 4000, and make sure your API endpoint (API_PREFIX) is set correctly to match your API port. If you have changed the API port, ensure the frontend knows the new API URL.

No evidence of version-specific bugs in v1.4.1 regarding port changes. If you follow the above, the port should change as expected.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Join Discord Share on X

@dosubot[bot] commented on GitHub (Jun 27, 2025): <!-- Greeting --> Hi @KuiliangL! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the dify team. <!-- Answer --> To change the Dify web frontend port when running from source, set the port using the environment variable PORT or the --port argument. The .env and .env.local files do not affect the web server port. The recommended way is: ```bash pnpm run start --port=4000 --host=0.0.0.0 ``` or set the environment variable: ```bash PORT=4000 pnpm run start ``` This works because the Next.js server (used by Dify's frontend) reads the PORT variable or --port argument at startup [web/README.md](https://github.com/langgenius/dify/blob/37e19de7ab3d8c1ffd8dfd8b789ff52b47f981cb/web/README.md) [web/next.config.js](https://github.com/langgenius/dify/blob/37e19de7ab3d8c1ffd8dfd8b789ff52b47f981cb/web/next.config.js). Your previous command `pnpm start -- -p 4000` does not work because the correct flag is `--port=4000`, not `-p 4000`. If you still get stuck on the install page, double-check that no other process is using port 4000, and make sure your API endpoint (API_PREFIX) is set correctly to match your API port. If you have changed the API port, ensure the frontend knows the new API URL. No evidence of version-specific bugs in v1.4.1 regarding port changes. If you follow the above, the port should change as expected. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/9d12875d-e357-425b-8498-80a1149ef4ec?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/9d12875d-e357-425b-8498-80a1149ef4ec?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/9d12875d-e357-425b-8498-80a1149ef4ec?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/9d12875d-e357-425b-8498-80a1149ef4ec?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/9d12875d-e357-425b-8498-80a1149ef4ec?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/9d12875d-e357-425b-8498-80a1149ef4ec?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/9d12875d-e357-425b-8498-80a1149ef4ec?feedback_type=other)</sup>&nbsp;&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/langgenius/dify/issues/21647)
Author
Owner

@KuiliangL commented on GitHub (Jun 28, 2025):

@dosu I tried the commands given above and found that they didn't work. I checked the code and found that in the new version, the port has been set to process.Env.PORT or 3000. It is currently unclear why changing the PORT port still does not work.
The reason for getting stuck in the web interface seems unrelated to port conflicts. I have two machines, one is the server and the other is the client. When I visited, I found that the URL I was accessing was localhost: port and did not access the server's IP address. The problem lies in the settings of NEXT_PULIC-API-PREFIX and NEXT_PULIC-PUBLIC-API-PREFIX, which require modifying the IP address. I also set the WEB_CPI_CORS.ALLOW-ORIGINS and CONSOLE-CORS.ALLOW-ORIGINS in the. env file to '*', and they can be accessed normally later.
Another question, have you tried deploying dify without using Docker in a non networked environment? Thank you for your reply!

@KuiliangL commented on GitHub (Jun 28, 2025): @dosu I tried the commands given above and found that they didn't work. I checked the code and found that in the new version, the port has been set to **_process.Env.PORT_** or 3000. It is currently unclear why changing the PORT port still does not work. The reason for getting stuck in the web interface seems unrelated to port conflicts. I have two machines, one is the server and the other is the client. When I visited, I found that the URL I was accessing was localhost: port and did not access the server's IP address. The problem lies in the settings of `NEXT_PULIC-API-PREFIX` and `NEXT_PULIC-PUBLIC-API-PREFIX`, which require modifying the IP address. I also set the `WEB_CPI_CORS.ALLOW-ORIGINS` and `CONSOLE-CORS.ALLOW-ORIGINS` in the. env file to '*', and they can be accessed normally later. Another question, have you tried deploying dify without using Docker in a non networked environment? Thank you for your reply!
Author
Owner

@dosubot[bot] commented on GitHub (Jun 28, 2025):

For changing the Dify web frontend port when running from source, the expected method is to use either the environment variable or the command-line argument, like this:

pnpm run start --port=4000 --host=0.0.0.0

or

PORT=4000 pnpm run start

This should work because the code uses process.env.PORT (defaulting to 3000) to set the port, and the start script is designed to honor these settings. The .env and .env.local files do not affect the web server port—only runtime environment variables or command-line arguments do. If the port still doesn't change, double-check for lingering processes on port 3000, shell environment issues, or cached build artifacts. There are no recent changes in the codebase that override this logic, and no custom server code blocks this behavior [web/package.json] [web/next.config.js] [web/README.md].

To make the frontend accessible from another machine, always use --host=0.0.0.0 so the server binds to all interfaces, not just localhost. Then, set NEXT_PUBLIC_API_PREFIX and NEXT_PUBLIC_PUBLIC_API_PREFIX to the server's IP and correct port, so the client can reach the backend. These must be reachable from your client machine, not just from the server itself [web/docker/entrypoint.sh].

For deploying Dify without Docker in a non-networked (air-gapped) environment: there is no official documentation, but it is possible. You need to pre-download all dependencies (Python, Node.js, system packages), build everything externally, and transfer the results to your internal network. For plugins, export plugin data and files from an external environment and import them manually. Initial database setup may also require manual intervention [issue 13003] [discussion 16373].

Let me know if you want a troubleshooting checklist for the port issue or more details on offline deployment steps.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Join Discord Share on X

@dosubot[bot] commented on GitHub (Jun 28, 2025): <!-- Answer --> For changing the Dify web frontend port when running from source, the expected method is to use either the environment variable or the command-line argument, like this: ``` pnpm run start --port=4000 --host=0.0.0.0 ``` or ``` PORT=4000 pnpm run start ``` This should work because the code uses `process.env.PORT` (defaulting to 3000) to set the port, and the start script is designed to honor these settings. The `.env` and `.env.local` files do not affect the web server port—only runtime environment variables or command-line arguments do. If the port still doesn't change, double-check for lingering processes on port 3000, shell environment issues, or cached build artifacts. There are no recent changes in the codebase that override this logic, and no custom server code blocks this behavior [[web/package.json](https://github.com/langgenius/dify/blob/37e19de7ab3d8c1ffd8dfd8b789ff52b47f981cb/web/package.json)] [[web/next.config.js](https://github.com/langgenius/dify/blob/37e19de7ab3d8c1ffd8dfd8b789ff52b47f981cb/web/next.config.js)] [[web/README.md](https://github.com/langgenius/dify/blob/37e19de7ab3d8c1ffd8dfd8b789ff52b47f981cb/web/README.md)]. To make the frontend accessible from another machine, always use `--host=0.0.0.0` so the server binds to all interfaces, not just localhost. Then, set `NEXT_PUBLIC_API_PREFIX` and `NEXT_PUBLIC_PUBLIC_API_PREFIX` to the server's IP and correct port, so the client can reach the backend. These must be reachable from your client machine, not just from the server itself [[web/docker/entrypoint.sh](https://github.com/langgenius/dify/blob/37e19de7ab3d8c1ffd8dfd8b789ff52b47f981cb/web/docker/entrypoint.sh)]. For deploying Dify without Docker in a non-networked (air-gapped) environment: there is no official documentation, but it is possible. You need to pre-download all dependencies (Python, Node.js, system packages), build everything externally, and transfer the results to your internal network. For plugins, export plugin data and files from an external environment and import them manually. Initial database setup may also require manual intervention [[issue 13003](https://github.com/langgenius/dify/issues/13003)] [[discussion 16373](https://github.com/langgenius/dify/discussions/16373)]. Let me know if you want a troubleshooting checklist for the port issue or more details on offline deployment steps. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/100ce114-7889-4ed6-b092-d56ed48c409d?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/100ce114-7889-4ed6-b092-d56ed48c409d?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/100ce114-7889-4ed6-b092-d56ed48c409d?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/100ce114-7889-4ed6-b092-d56ed48c409d?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/100ce114-7889-4ed6-b092-d56ed48c409d?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/100ce114-7889-4ed6-b092-d56ed48c409d?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/100ce114-7889-4ed6-b092-d56ed48c409d?feedback_type=other)</sup>&nbsp;&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/langgenius/dify/issues/21647)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#14968