Strapi PM2 GraphQL Error

System Information
  • Strapi Version: 3.2.0
  • Operating System: OS
  • Database: MongoDB
  • Node Version: 12.9
  • NPM Version: 6.14.5
  • Yarn Version:

I have uploaded my React Front End to nginx and everything is running statically. I have added Strapi to the pm2 and set up and config.js file that has everything running on it. It tells me the config file is online. I go to my website and I do not see anything from strapi on it and it tells me i have an GraphQL error.

POST http://localhost:1337/graphql net::ERR_CONNECTION_REFUSED

This is the Code that I have in my PM2 file:

module.exports = {
apps: [{
name: ‘strapi’,
cwd: ‘/var/www/’,
script: ‘npm’,
args: ‘start’

I then pm2 start ecosystem.config.js and it runs the file and says my strapi server is online. Then I go to my website and refresh and get that GraphQL error. If anyone can help I would greatly appreciate it.

Where exactly do you see this error, in browser’s console? If this is from browser, can you share also the pm2 logs if you have something there.
This error occurs only when you are trying to access /graphql path or you get it even on http://localhost:1337/?

Yes when i go to my website the graphql error is in the console

When I have the server running on the localhost I can access Strapi. I tested that when I went to website and localhost is running on my personal computer I can see all the stuff that i have uploadedt to strapi

When I pm2 logs strapi

To manage your projcet go to the administration panel at:
then server would just be without the admin

When I try to go to either/or i get an error the webpage isnt found

Can you share the /config/server.js from strapi.
Take care to not share some private envs if you have defined them there. (JWT, passwords, etc)

As I see you call the localhost from the live website, why don’t you upload strapi somewhere and define its route in your React App

module.exports = ({ env }) => ({
host: env(‘HOST’, ‘’),
port:‘PORT’, 1337),

This is my server.js file

So everything works when localhost is live on your computer, but doesn’t work when its off?

Correct. I go to the server file and start strapi and run in and refresh the webpage and everything is working. But when I kill the app and have Strapi running in pm2 it fails. Then gives me that GraphQL error.

Can you share the error from pm2?
pm2 logs

Well theres no error. It tells me everything is online and i can manage my project at Thats what im confused about. It says strapi is online and running.

Can you modify your /config/server.js to

module.exports = ({ env }) => ({
 host: env(‘HOST’, ‘’),
 port:‘PORT’, 1337),

And try again

Do i need to change anything in my PM2 file i sent? Up top

No, the pm2’s ecosystem file is ok

Ok. I will push the code and pull it down on digital ocean and let you know. I moved some files around so i need to move the git repository into the correct folder and pull it down. Will keep you updated and hopefully this works!

Wait a second, so your strapi is on digital Ocean? But you are trying to access it with http://localhost url from react app?

Well yes. I was going off the docs and thats why I was confused. I apologize for any confusion. I should have said I was using Nginx and PM2 inside of digital ocean. I have everything stored in the server folder on Digital ocean hence that CWD on top. If that makes anything easier?

Oh, you are doing it wrong, you should expose your strapi with nginx and configure its url in react.

I was told to use nginx to make it static and then run strapi on PM2? I asked multiple times and was told this is the best approach? I also already have the URL set up on nginx as well too with the IP address. Is there anyway to work around this or i have to change it. And if so is there docs to support your process?

If you have your strapi exposed on the ip address then change it in react. I will share tomorrow some doc urls.

Cool. Thank you!!

By any chance did you find any Docs?