Deployment of NuxtJS 3 on cPanel

anyone deployed nuxtjs with pm2 on capnel and can point in the right direction? I have set up proxy server as required and it works, but the nuxt give me this error:
TypeError: Invalid URL
0|[app-name] | at new URL (node:internal/url:825:25)
0|[app-name] | at getRequestURL (file:///home/[username]/[path-to-your-app]/.output/server/chunks/nitro/nitro.mjs:1068:10)
0|[app-name] | at defaultHandler (file:///home/[username]/[path-to-your-app]/.output/server/chunks/nitro/nitro.mjs:5440:15)
0|[app-name] | at defaultNitroErrorHandler (file:///home/[username]/[path-to-your-app]/.output/server/chunks/nitro/nitro.mjs:5430:17)
0|[app-name] | at errorHandler (file:///home/[username]/[path-to-your-app]/.output/server/chunks/nitro/nitro.mjs:5494:13)
0|[app-name] | at processTicksAndRejections (node:internal/process/task_queues:105:5)
0|[app-name] | at Server.toNodeHandle (file:///home/[username]/[path-to-your-app]/.output/server/chunks/nitro/nitro.mjs:2200:9) {
0|[app-name] | code: 'ERR_INVALID_URL',
0|[app-name] | input: '/',
0|[app-name] | base: 'https://[your-domain], [your-domain]'
0|[app-name] | }
TypeError: Invalid URL
0|[app-name] | at new URL (node:internal/url:825:25)
0|[app-name] | at getRequestURL (file:///home/[username]/[path-to-your-app]/.output/server/chunks/nitro/nitro.mjs:1068:10)
0|[app-name] | at defaultHandler (file:///home/[username]/[path-to-your-app]/.output/server/chunks/nitro/nitro.mjs:5440:15)
0|[app-name] | at defaultNitroErrorHandler (file:///home/[username]/[path-to-your-app]/.output/server/chunks/nitro/nitro.mjs:5430:17)
0|[app-name] | at errorHandler (file:///home/[username]/[path-to-your-app]/.output/server/chunks/nitro/nitro.mjs:5494:13)
0|[app-name] | at processTicksAndRejections (node:internal/process/task_queues:105:5)
0|[app-name] | at Server.toNodeHandle (file:///home/[username]/[path-to-your-app]/.output/server/chunks/nitro/nitro.mjs:2200:9) {
0|[app-name] | code: 'ERR_INVALID_URL',
0|[app-name] | input: '/',
0|[app-name] | base: 'https://[your-domain], [your-domain]'
0|[app-name] | }
on the nuxt app itself (the domain), this is what I see:
{
"statusCode": 500,
"stack": []
}
{
"statusCode": 500,
"stack": []
}
The include.conf files in the server on ssl/2_4/cpaneluser/domain and std/2_4/cpaneluser/domain are correctly configured
2 Replies
kapa.ai
kapa.ai3mo ago
Hi @Shay Rosenfeld. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Based on the knowledge sources provided, there is no direct documentation or example specifically about deploying Nuxt 3 with PM2 on cPanel. However, your error message:
TypeError: Invalid URL
...
code: 'ERR_INVALID_URL',
input: '/',
base: '<https://[your-domain],> [your-domain]'
TypeError: Invalid URL
...
code: 'ERR_INVALID_URL',
input: '/',
base: '<https://[your-domain],> [your-domain]'
suggests that the base URL being constructed by Nitro (the Nuxt server engine) is invalid, likely due to a misconfiguration in your environment or proxy setup. Here are some relevant points and suggestions based on the sources: 1. Base URL Configuration
Ensure that your app.baseURL in nuxt.config.js is set correctly. If your app is served from the root, it should be /. If it's in a subdirectory, set it to that subdirectory (e.g., /app/). Incorrect base URLs can cause asset and routing issues, especially behind proxies or in subdirectory deployments. See the Nuxt app configuration docs. 2. Proxy and Reverse Proxy
When deploying behind a proxy (like Apache or Nginx, which cPanel often uses), make sure your proxy configuration forwards the correct headers, especially Host and X-Forwarded-Proto. This helps Nitro construct the correct absolute URLs. Example Nginx config for Nuxt:
location / {
proxy_pass <http://localhost:3000;>
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
}

location / {
proxy_pass <http://localhost:3000;>
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
}

See example 3. PM2 Configuration
Your PM2 config should point to .output/server/index.mjs and set the correct port. Example:
module.exports = {
apps: [
{
name: 'NuxtAppName',
port: '3000',
exec_mode: 'cluster',
instances: 'max',
script: './.output/server/index.mjs'
}
]
}

module.exports = {
apps: [
{
name: 'NuxtAppName',
port: '3000',
exec_mode: 'cluster',
instances: 'max',
script: './.output/server/index.mjs'
}
]
}

See deployment docs 4. Check for Double Domain in Base
The error shows base: '<https://[your-domain],> [your-domain]', which looks like a misconfigured environment variable or header. Make sure you are not setting the base URL or related environment variables with a comma or multiple domains. 5. General Troubleshooting
- Double-check your proxy and environment variable setup. - Make sure you are not setting NUXT_APP_BASE_URL or similar variables incorrectly. - If using SSL, ensure your proxy handles SSL termination and forwards requests to Nuxt over HTTP, unless you have configured Nitro to handle SSL directly (not recommended for production) see deployment docs. Summary:
The error is likely due to a misconfiguration in your proxy or environment variables, causing Nitro to receive an invalid base URL. Double-check your nuxt.config.js (app.baseURL), your proxy headers, and any environment variables related to the base URL or host. If you are deploying in a subdirectory, ensure all related settings and proxy rules match that subdirectory. If you need more specific help, please provide your nuxt.config.js and the relevant proxy configuration. The knowledge sources do not contain a cPanel-specific guide, but the general Nuxt 3 deployment and proxying principles apply. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai3mo ago
<@578603590927646754> Kapa.ai is still learning and improving, please let me know how I did by reacting below.

Did you find this page helpful?