Am working on a nuxt 3 app project and wish to deploy to my forge server. I've followed the steps from the link below
https://github.com/nuxt/docs/blob/master/en/faq/laravel-forge-deployment.md
But after i click deploy and my site is deployed successfully, i get a 502 bad gateway error when i visit my site domain. Can someone help me out here please
To resolve the 502 Bad Gateway error when deploying a Nuxt 3 app to a Laravel Forge server, you can follow these steps to ensure your setup is correct:
Check the Build Process:
Ensure that your Nuxt 3 app is properly built before deployment. You can do this by running the build command locally to see if there are any errors:
npm run build
Verify the Deployment Script:
Make sure your deployment script on Laravel Forge is correctly set up to build and start your Nuxt app. A typical deployment script might look like this:
# Navigate to the project directory
cd /home/forge/your-domain.com
# Pull the latest changes from the repository
git pull origin main
# Install dependencies
npm install
# Build the application
npm run build
# Restart the process manager (e.g., PM2)
pm2 restart all
Check the Process Manager:
Ensure that you are using a process manager like PM2 to run your Nuxt app. If PM2 is not installed, you can install it globally:
npm install -g pm2
Then, start your Nuxt app using PM2:
pm2 start npm --name "nuxt-app" -- start
Verify the Server Configuration:
Ensure that your server is configured to proxy requests to the correct port where your Nuxt app is running. For example, if your Nuxt app is running on port 3000, your Nginx configuration should include:
Check Logs for Errors:
Look at the logs for any errors that might give you more information about the 502 error. You can check the Nginx error logs and the logs for your Nuxt app (if using PM2, you can use pm2 logs).
Firewall and Port Configuration:
Ensure that the port your Nuxt app is running on is open and accessible. You might need to adjust your firewall settings to allow traffic on that port.
By following these steps, you should be able to identify and resolve the issue causing the 502 Bad Gateway error. If the problem persists, double-check each configuration step and ensure that all services are running as expected.
Make sure you add your environment variables before you deploy your application
Do not forget to replace all variables I added by the right information you should have and if you have any issues or difficulties just leave a comment here and I'll help out as much as I can
@Shiro1101 seems it doesn't work for ip address.
can you also try Nuxt3 CSR(ssr:false) with raw ip?
i can't figure out what is the correct nginx conf or ecosystem.config.cjs for this.
it sometimes display but it makes preflight options request not post(since I use nuxt apollo all should be post)
I set up cors properly, so my app from local and vercel works fine, only Forge deployment failed.