1

I am trying to deploy a nuxt app to cpanel shared hosting. It is working fine on my local machine using run dev, build and start. However, when I moved the files to cpanel. I can run npm dev, build, and start. When I use npm run dev, an IP and port was generated, I visited this IP and port on my browser but its not working.

How can I make this IP work as well as make the app work with my domain.

enter image description here

6
  • Hmm... This is a bit more complex, just so you are aware. I usually stick with hosting providers that matches the stack that I work with, because it is quite often a shit-show getting everything to work. So yeah, in theory, you could purchase some server in Moldova, deploy your app there (and fiddle with it until it works). But it will most likely be very time consuming. ... I think the problem is that the server has to map they external domain/IP to the internal application. And in order to do that, we would have to know a lot more about the setup. Commented Dec 20, 2021 at 12:25
  • Also, what is the kind of IP given here? Local or external? Easiest way is to ship Nuxt to Netlify if you're using taget: 'static'. Commented Dec 20, 2021 at 12:26
  • @kissu It is an external IP, I'm using target: 'server'. Also, I know how to deploy on vercel/netlify which are quite easy to setup but cpanel is whats available as a host for this project which I know its possible and I'm willing to learn how to Commented Dec 20, 2021 at 12:36
  • @Zeth what would you want me to share about the setup? Commented Dec 20, 2021 at 12:39
  • See, that's the thing with big questions like this. It's hard to ask for, what is relevant, since I don't know enough about the setup. It's a bit like 'The chicken or the egg' - I know. But you can start with: Q1: Which hosting provider you're using. Q2: If they're using Nginx, Apache or which server-technology they're using to serve the content. Q3: If there are any other applications running on the server. Q4: If those other applications are sharing the same stack. You can update your question with the answer. But I think I had Googled for 'Deploy Vue/Nuxt app' and find a tailored solution. Commented Dec 20, 2021 at 12:43

1 Answer 1

2

for run nuxt ssr in cpanel you can use below code and install pm2 in your project:

1-package.json:

"config": {
    "nuxt": {
      "host": "0.0.0.0",
      "port": "customport"
    }
  },
  "scripts": {
    "dev": "nuxt --host yourdomain --port customport",
    "build": "nuxt build",
    "start": "nuxt start",
    "generate": "nuxt generate",
    "deploy": "/opt/cpanel/ea-nodejs10/bin/pm2 start /opt/cpanel/ea-nodejs10/bin/npm --name yourpm2name -- start"
  },

2-.htaccess file

RewriteEngine On
RewriteCond %{SERVER_PORT} 443
RewriteRule ^index.php(.*) http://yourdomain::customport/$1 [P,L]
RewriteRule (.*) http://yourdomain:customport/$1 [P,L]

3- run this code: npm run build 4- and then: pm2 start yourpm2name

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.