Getting error "POST https://mydomain.com/api/v1/widgets/session/initialize 404 (Not Found)
my .env example
Root URL
REACT_APP_WS_URL=$HOST_NAME/ws
API_ROOT_URL=$HOST_NAME/api
DISABLE_USER_REGISTRATION=true
FRONT_BASE_URL=$HOST_NAME
WIDGET_EMBED_PATH=$HOST_NAME:4701/embed.umd.min.js
WIDGET_URL=$HOST_NAME/widget
Context Paths
Only needed for setups with reverse-proxies
GLOBAL_CONTEXT_PATH=
WEB_CONTEXT_PATH=
API_CONTEXT_PATH=api
WS_CONTEXT_PATH=ws
WIDGET_CONTEXT_PATH=widget
nginx vhost for novu
location /api {
# Redirect API requests to HTTPS
#rewrite ^/api(.*)$ https://$http_host/api$1 permanent;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_pass http://localhost:3000/api;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
location /widget {
proxy_pass http://localhost:4500/widget;
proxy_http_version 1.1;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
Can anyone guide me why I am getting above error (I deployed docker based self-hosted Novu)
https://docs.novu.co/self-hosting-novu/deploy-with-docker?utm_campaign=website
4 Replies
Hi @Ibrar Ansari, I'm an AI assistant for Novu. While a team member reviews this question, I'll see if I can find relevant sources for your question.
-----------------------------
While I generate an answer, here are some sources that might be helpful:
* Deploy with Docker
* AWS
* Run Novu in local machine
* Object Storage (S3, Blob, GCS)
-----------------------------
Answer
Based on the
.env
configuration and nginx vhost setup you've provided, it seems like you're configuring Novu to work behind an nginx reverse proxy. The error "POST https://mydomain.com/api/v1/widgets/session/initialize 404 (Not Found)" indicates that the request to the API endpoint is not being routed correctly to your Novu service.
The API_CONTEXT_PATH=api
in your .env
file suggests that your API should be accessible under the /api
path. However, your nginx configuration for the /api
location is proxying requests to http://localhost:3000/api
. Given your setup, it's possible that the issue lies in how the context path is being handled by nginx or the Novu configuration.
To troubleshoot this issue, consider the following adjustments:
1. Nginx Configuration: Ensure that the proxy_pass directive does not append the /api
path again to the proxied request. This can lead to requests being sent to http://localhost:3000/api/api/v1/widgets/session/initialize
instead of the correct http://localhost:3000/api/v1/widgets/session/initialize
. Modify your nginx configuration like this:
This change ensures that a request to https://mydomain.com/api/v1/widgets/session/initialize
is correctly proxied to http://localhost:3000/api/v1/widgets/session/initialize
.
2. Environment Variables: Double-check the environment variables in your .env
file, especially the $HOST_NAME
variable, to ensure they are correctly set and accessible by Novu. Incorrect environment variables can lead to improper URL resolutions.
3. Context Path Configuration: From the information provided, it's not clear if additional configuration within Novu is required to fully support the API_CONTEXT_PATH
. The official documentation does not specify detailed steps for configuring context paths within Novu itself for reverse proxy setups. However, the general guidance on reverse-proxy/load balancers setup suggests setting the GLOBAL_CONTEXT_PATH
for the base path of the application and adjusting API_CONTEXT_PATH
, WIDGET_CONTEXT_PATH
, and WS_CONTEXT_PATH
accordingly (1) . If Novu version you're using supports these environment variables directly for reverse proxy setups, ensure they are correctly set. Otherwise, handling context paths might need to be managed entirely by nginx.
4. Novu and Docker Configuration: Ensure your Docker-based Novu deployment is correctly set up according to the official documentation. Verify that the Novu containers are running and accessible on their respective ports (3000
for API, 4500
for widget service, etc.) on the host machine.
If after making these adjustments, you're still facing issues, it might be beneficial to check the Novu and nginx logs for any additional errors or warnings that can provide more insight into the problem. Additionally, consider reviewing the Novu community discussions or reaching out for support for more specific guidance onreverse proxy configurations with Novu.
Got it. Tagging @Support for additional help.
@Support please give me solution as soon as possible