CentOS 7 PM2 Application - 502 Bad Gateway










0















I have a default Laravel application running on port 80. It use PHP 7 default setup. Now I want to add another nodejs apps which usually running on port 3000 and use reverse proxy on Nginx from port 8000 to 3000. But it turn out to be 502 bad gateway. Here is my pm2 status



┌──────────┬────┬─────────┬──────┬───────┬────────┬─────────┬────────┬─────┬───────────┬──────┬──────────┐
│ App name │ id │ version │ mode │ pid │ status │ restart │ uptime │ cpu │ mem │ user │ watching │
├──────────┼────┼─────────┼──────┼───────┼────────┼─────────┼────────┼─────┼───────────┼──────┼──────────┤
│ FAM │ 0 │ 1.0.0 │ fork │ 16073 │ online │ 0 │ 97m │ 0% │ 48.4 MB │ root │ disabled │
└──────────┴────┴─────────┴──────┴───────┴────────┴─────────┴────────┴─────┴───────────┴──────┴──────────┘
Use `pm2 show <id|name>` to get more details about an app


I suspect the real reason of 502 is because the user is root so I change all my js files ownership to



-rw-r--r-- 1 apache apache 273 Nov 13 16:19 README.md
drwxr-xr-x 4 apache apache 4096 Nov 14 21:28 components
drwxr-xr-x 2 apache apache 4096 Nov 14 21:28 core
-rw-r--r-- 1 apache apache 693 Nov 15 17:30 ecosystem.config.js
-rw-r--r-- 1 apache apache 508 Nov 14 21:28 env.js
drwxr-xr-x 798 root root 28672 Nov 15 21:40 node_modules
-rw-r--r-- 1 apache apache 372088 Nov 15 21:40 package-lock.json
-rw-r--r-- 1 apache apache 1971 Nov 14 21:28 package.json
-rw-r--r-- 1 apache apache 1621 Nov 14 21:28 server.js
drwxr-xr-x 5 apache apache 4096 Nov 14 21:28 static
drwxr-xr-x 3 apache apache 4096 Nov 14 21:28 styles


I have expose the 8000 port on firewall-cmd as well add it to /etc/service. But it all failed.



Here is the nginx default conf (/etc/nginx/nginx.conf)



# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events
worker_connections 1024;


http
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;

sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;

include /etc/nginx/mime.types;
default_type application/octet-stream;

# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;

upstream fam_upstream
server 127.0.0.1:3000;
keepalive 64;


server
listen 80;
listen [::]:80 default_server;
server_name _;
root /var/www/html/laravel/public;
index index.php;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;

location /
try_files $uri $uri/ /index.php?$query_string;


location ~ [^/].php(/

# Settings for a TLS enabled server.
#
# server
# listen 443 ssl http2 default_server;
# listen [::]:443 ssl http2 default_server;
# server_name _;
# root /usr/share/nginx/html;
#
# ssl_certificate "/etc/pki/nginx/server.crt";
# ssl_certificate_key "/etc/pki/nginx/private/server.key";
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 10m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
#
# # Load configuration files for the default server block.
# include /etc/nginx/default.d/*.conf;
#
# location /
#
#
# error_page 404 /404.html;
# location = /40x.html
#
#
# error_page 500 502 503 504 /50x.html;
# location = /50x.html
#
#




For your information, this VPS has no domain name set yet. So it all run on regular http.



And here is conf for 8000 port



upstream fam-app 
server <VPS_IP>:3000;


server
listen 8000;
location /
proxy_set_header X-NginX-Proxy true;
proxy_pass http://fam-app/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect off;
proxy_max_temp_file_size 0;
proxy_read_timeout 240s;





Most solution shows how to run pm2 and nginx on Ubuntu but not much about Centos 7. What do you think?










share|improve this question




























    0















    I have a default Laravel application running on port 80. It use PHP 7 default setup. Now I want to add another nodejs apps which usually running on port 3000 and use reverse proxy on Nginx from port 8000 to 3000. But it turn out to be 502 bad gateway. Here is my pm2 status



    ┌──────────┬────┬─────────┬──────┬───────┬────────┬─────────┬────────┬─────┬───────────┬──────┬──────────┐
    │ App name │ id │ version │ mode │ pid │ status │ restart │ uptime │ cpu │ mem │ user │ watching │
    ├──────────┼────┼─────────┼──────┼───────┼────────┼─────────┼────────┼─────┼───────────┼──────┼──────────┤
    │ FAM │ 0 │ 1.0.0 │ fork │ 16073 │ online │ 0 │ 97m │ 0% │ 48.4 MB │ root │ disabled │
    └──────────┴────┴─────────┴──────┴───────┴────────┴─────────┴────────┴─────┴───────────┴──────┴──────────┘
    Use `pm2 show <id|name>` to get more details about an app


    I suspect the real reason of 502 is because the user is root so I change all my js files ownership to



    -rw-r--r-- 1 apache apache 273 Nov 13 16:19 README.md
    drwxr-xr-x 4 apache apache 4096 Nov 14 21:28 components
    drwxr-xr-x 2 apache apache 4096 Nov 14 21:28 core
    -rw-r--r-- 1 apache apache 693 Nov 15 17:30 ecosystem.config.js
    -rw-r--r-- 1 apache apache 508 Nov 14 21:28 env.js
    drwxr-xr-x 798 root root 28672 Nov 15 21:40 node_modules
    -rw-r--r-- 1 apache apache 372088 Nov 15 21:40 package-lock.json
    -rw-r--r-- 1 apache apache 1971 Nov 14 21:28 package.json
    -rw-r--r-- 1 apache apache 1621 Nov 14 21:28 server.js
    drwxr-xr-x 5 apache apache 4096 Nov 14 21:28 static
    drwxr-xr-x 3 apache apache 4096 Nov 14 21:28 styles


    I have expose the 8000 port on firewall-cmd as well add it to /etc/service. But it all failed.



    Here is the nginx default conf (/etc/nginx/nginx.conf)



    # For more information on configuration, see:
    # * Official English Documentation: http://nginx.org/en/docs/
    # * Official Russian Documentation: http://nginx.org/ru/docs/

    user nginx;
    worker_processes auto;
    error_log /var/log/nginx/error.log;
    pid /run/nginx.pid;

    # Load dynamic modules. See /usr/share/nginx/README.dynamic.
    include /usr/share/nginx/modules/*.conf;

    events
    worker_connections 1024;


    http
    log_format main '$remote_addr - $remote_user [$time_local] "$request" '
    '$status $body_bytes_sent "$http_referer" '
    '"$http_user_agent" "$http_x_forwarded_for"';

    access_log /var/log/nginx/access.log main;

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    upstream fam_upstream
    server 127.0.0.1:3000;
    keepalive 64;


    server
    listen 80;
    listen [::]:80 default_server;
    server_name _;
    root /var/www/html/laravel/public;
    index index.php;
    # Load configuration files for the default server block.
    include /etc/nginx/default.d/*.conf;

    location /
    try_files $uri $uri/ /index.php?$query_string;


    location ~ [^/].php(/

    # Settings for a TLS enabled server.
    #
    # server
    # listen 443 ssl http2 default_server;
    # listen [::]:443 ssl http2 default_server;
    # server_name _;
    # root /usr/share/nginx/html;
    #
    # ssl_certificate "/etc/pki/nginx/server.crt";
    # ssl_certificate_key "/etc/pki/nginx/private/server.key";
    # ssl_session_cache shared:SSL:1m;
    # ssl_session_timeout 10m;
    # ssl_ciphers HIGH:!aNULL:!MD5;
    # ssl_prefer_server_ciphers on;
    #
    # # Load configuration files for the default server block.
    # include /etc/nginx/default.d/*.conf;
    #
    # location /
    #
    #
    # error_page 404 /404.html;
    # location = /40x.html
    #
    #
    # error_page 500 502 503 504 /50x.html;
    # location = /50x.html
    #
    #




    For your information, this VPS has no domain name set yet. So it all run on regular http.



    And here is conf for 8000 port



    upstream fam-app 
    server <VPS_IP>:3000;


    server
    listen 8000;
    location /
    proxy_set_header X-NginX-Proxy true;
    proxy_pass http://fam-app/;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_redirect off;
    proxy_max_temp_file_size 0;
    proxy_read_timeout 240s;





    Most solution shows how to run pm2 and nginx on Ubuntu but not much about Centos 7. What do you think?










    share|improve this question


























      0












      0








      0








      I have a default Laravel application running on port 80. It use PHP 7 default setup. Now I want to add another nodejs apps which usually running on port 3000 and use reverse proxy on Nginx from port 8000 to 3000. But it turn out to be 502 bad gateway. Here is my pm2 status



      ┌──────────┬────┬─────────┬──────┬───────┬────────┬─────────┬────────┬─────┬───────────┬──────┬──────────┐
      │ App name │ id │ version │ mode │ pid │ status │ restart │ uptime │ cpu │ mem │ user │ watching │
      ├──────────┼────┼─────────┼──────┼───────┼────────┼─────────┼────────┼─────┼───────────┼──────┼──────────┤
      │ FAM │ 0 │ 1.0.0 │ fork │ 16073 │ online │ 0 │ 97m │ 0% │ 48.4 MB │ root │ disabled │
      └──────────┴────┴─────────┴──────┴───────┴────────┴─────────┴────────┴─────┴───────────┴──────┴──────────┘
      Use `pm2 show <id|name>` to get more details about an app


      I suspect the real reason of 502 is because the user is root so I change all my js files ownership to



      -rw-r--r-- 1 apache apache 273 Nov 13 16:19 README.md
      drwxr-xr-x 4 apache apache 4096 Nov 14 21:28 components
      drwxr-xr-x 2 apache apache 4096 Nov 14 21:28 core
      -rw-r--r-- 1 apache apache 693 Nov 15 17:30 ecosystem.config.js
      -rw-r--r-- 1 apache apache 508 Nov 14 21:28 env.js
      drwxr-xr-x 798 root root 28672 Nov 15 21:40 node_modules
      -rw-r--r-- 1 apache apache 372088 Nov 15 21:40 package-lock.json
      -rw-r--r-- 1 apache apache 1971 Nov 14 21:28 package.json
      -rw-r--r-- 1 apache apache 1621 Nov 14 21:28 server.js
      drwxr-xr-x 5 apache apache 4096 Nov 14 21:28 static
      drwxr-xr-x 3 apache apache 4096 Nov 14 21:28 styles


      I have expose the 8000 port on firewall-cmd as well add it to /etc/service. But it all failed.



      Here is the nginx default conf (/etc/nginx/nginx.conf)



      # For more information on configuration, see:
      # * Official English Documentation: http://nginx.org/en/docs/
      # * Official Russian Documentation: http://nginx.org/ru/docs/

      user nginx;
      worker_processes auto;
      error_log /var/log/nginx/error.log;
      pid /run/nginx.pid;

      # Load dynamic modules. See /usr/share/nginx/README.dynamic.
      include /usr/share/nginx/modules/*.conf;

      events
      worker_connections 1024;


      http
      log_format main '$remote_addr - $remote_user [$time_local] "$request" '
      '$status $body_bytes_sent "$http_referer" '
      '"$http_user_agent" "$http_x_forwarded_for"';

      access_log /var/log/nginx/access.log main;

      sendfile on;
      tcp_nopush on;
      tcp_nodelay on;
      keepalive_timeout 65;
      types_hash_max_size 2048;

      include /etc/nginx/mime.types;
      default_type application/octet-stream;

      # Load modular configuration files from the /etc/nginx/conf.d directory.
      # See http://nginx.org/en/docs/ngx_core_module.html#include
      # for more information.
      include /etc/nginx/conf.d/*.conf;

      upstream fam_upstream
      server 127.0.0.1:3000;
      keepalive 64;


      server
      listen 80;
      listen [::]:80 default_server;
      server_name _;
      root /var/www/html/laravel/public;
      index index.php;
      # Load configuration files for the default server block.
      include /etc/nginx/default.d/*.conf;

      location /
      try_files $uri $uri/ /index.php?$query_string;


      location ~ [^/].php(/

      # Settings for a TLS enabled server.
      #
      # server
      # listen 443 ssl http2 default_server;
      # listen [::]:443 ssl http2 default_server;
      # server_name _;
      # root /usr/share/nginx/html;
      #
      # ssl_certificate "/etc/pki/nginx/server.crt";
      # ssl_certificate_key "/etc/pki/nginx/private/server.key";
      # ssl_session_cache shared:SSL:1m;
      # ssl_session_timeout 10m;
      # ssl_ciphers HIGH:!aNULL:!MD5;
      # ssl_prefer_server_ciphers on;
      #
      # # Load configuration files for the default server block.
      # include /etc/nginx/default.d/*.conf;
      #
      # location /
      #
      #
      # error_page 404 /404.html;
      # location = /40x.html
      #
      #
      # error_page 500 502 503 504 /50x.html;
      # location = /50x.html
      #
      #




      For your information, this VPS has no domain name set yet. So it all run on regular http.



      And here is conf for 8000 port



      upstream fam-app 
      server <VPS_IP>:3000;


      server
      listen 8000;
      location /
      proxy_set_header X-NginX-Proxy true;
      proxy_pass http://fam-app/;
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection 'upgrade';
      proxy_set_header Host $host;
      proxy_cache_bypass $http_upgrade;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_redirect off;
      proxy_max_temp_file_size 0;
      proxy_read_timeout 240s;





      Most solution shows how to run pm2 and nginx on Ubuntu but not much about Centos 7. What do you think?










      share|improve this question
















      I have a default Laravel application running on port 80. It use PHP 7 default setup. Now I want to add another nodejs apps which usually running on port 3000 and use reverse proxy on Nginx from port 8000 to 3000. But it turn out to be 502 bad gateway. Here is my pm2 status



      ┌──────────┬────┬─────────┬──────┬───────┬────────┬─────────┬────────┬─────┬───────────┬──────┬──────────┐
      │ App name │ id │ version │ mode │ pid │ status │ restart │ uptime │ cpu │ mem │ user │ watching │
      ├──────────┼────┼─────────┼──────┼───────┼────────┼─────────┼────────┼─────┼───────────┼──────┼──────────┤
      │ FAM │ 0 │ 1.0.0 │ fork │ 16073 │ online │ 0 │ 97m │ 0% │ 48.4 MB │ root │ disabled │
      └──────────┴────┴─────────┴──────┴───────┴────────┴─────────┴────────┴─────┴───────────┴──────┴──────────┘
      Use `pm2 show <id|name>` to get more details about an app


      I suspect the real reason of 502 is because the user is root so I change all my js files ownership to



      -rw-r--r-- 1 apache apache 273 Nov 13 16:19 README.md
      drwxr-xr-x 4 apache apache 4096 Nov 14 21:28 components
      drwxr-xr-x 2 apache apache 4096 Nov 14 21:28 core
      -rw-r--r-- 1 apache apache 693 Nov 15 17:30 ecosystem.config.js
      -rw-r--r-- 1 apache apache 508 Nov 14 21:28 env.js
      drwxr-xr-x 798 root root 28672 Nov 15 21:40 node_modules
      -rw-r--r-- 1 apache apache 372088 Nov 15 21:40 package-lock.json
      -rw-r--r-- 1 apache apache 1971 Nov 14 21:28 package.json
      -rw-r--r-- 1 apache apache 1621 Nov 14 21:28 server.js
      drwxr-xr-x 5 apache apache 4096 Nov 14 21:28 static
      drwxr-xr-x 3 apache apache 4096 Nov 14 21:28 styles


      I have expose the 8000 port on firewall-cmd as well add it to /etc/service. But it all failed.



      Here is the nginx default conf (/etc/nginx/nginx.conf)



      # For more information on configuration, see:
      # * Official English Documentation: http://nginx.org/en/docs/
      # * Official Russian Documentation: http://nginx.org/ru/docs/

      user nginx;
      worker_processes auto;
      error_log /var/log/nginx/error.log;
      pid /run/nginx.pid;

      # Load dynamic modules. See /usr/share/nginx/README.dynamic.
      include /usr/share/nginx/modules/*.conf;

      events
      worker_connections 1024;


      http
      log_format main '$remote_addr - $remote_user [$time_local] "$request" '
      '$status $body_bytes_sent "$http_referer" '
      '"$http_user_agent" "$http_x_forwarded_for"';

      access_log /var/log/nginx/access.log main;

      sendfile on;
      tcp_nopush on;
      tcp_nodelay on;
      keepalive_timeout 65;
      types_hash_max_size 2048;

      include /etc/nginx/mime.types;
      default_type application/octet-stream;

      # Load modular configuration files from the /etc/nginx/conf.d directory.
      # See http://nginx.org/en/docs/ngx_core_module.html#include
      # for more information.
      include /etc/nginx/conf.d/*.conf;

      upstream fam_upstream
      server 127.0.0.1:3000;
      keepalive 64;


      server
      listen 80;
      listen [::]:80 default_server;
      server_name _;
      root /var/www/html/laravel/public;
      index index.php;
      # Load configuration files for the default server block.
      include /etc/nginx/default.d/*.conf;

      location /
      try_files $uri $uri/ /index.php?$query_string;


      location ~ [^/].php(/

      # Settings for a TLS enabled server.
      #
      # server
      # listen 443 ssl http2 default_server;
      # listen [::]:443 ssl http2 default_server;
      # server_name _;
      # root /usr/share/nginx/html;
      #
      # ssl_certificate "/etc/pki/nginx/server.crt";
      # ssl_certificate_key "/etc/pki/nginx/private/server.key";
      # ssl_session_cache shared:SSL:1m;
      # ssl_session_timeout 10m;
      # ssl_ciphers HIGH:!aNULL:!MD5;
      # ssl_prefer_server_ciphers on;
      #
      # # Load configuration files for the default server block.
      # include /etc/nginx/default.d/*.conf;
      #
      # location /
      #
      #
      # error_page 404 /404.html;
      # location = /40x.html
      #
      #
      # error_page 500 502 503 504 /50x.html;
      # location = /50x.html
      #
      #




      For your information, this VPS has no domain name set yet. So it all run on regular http.



      And here is conf for 8000 port



      upstream fam-app 
      server <VPS_IP>:3000;


      server
      listen 8000;
      location /
      proxy_set_header X-NginX-Proxy true;
      proxy_pass http://fam-app/;
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection 'upgrade';
      proxy_set_header Host $host;
      proxy_cache_bypass $http_upgrade;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_redirect off;
      proxy_max_temp_file_size 0;
      proxy_read_timeout 240s;





      Most solution shows how to run pm2 and nginx on Ubuntu but not much about Centos 7. What do you think?







      node.js laravel nginx centos7 pm2






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 16 '18 at 4:02







      Muhaimin CS

















      asked Nov 15 '18 at 15:29









      Muhaimin CSMuhaimin CS

      8211




      8211






















          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53322727%2fcentos-7-pm2-application-502-bad-gateway%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53322727%2fcentos-7-pm2-application-502-bad-gateway%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          How to read a connectionString WITH PROVIDER in .NET Core?

          In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

          Museum of Modern and Contemporary Art of Trento and Rovereto