Приложение CentOS 7 PM2 - 502 Bad Gateway - PullRequest
0 голосов
/ 15 ноября 2018

У меня есть приложение по умолчанию Приложение Laravel , работающее на порту 80. Оно использует установку по умолчанию PHP 7. Теперь я хочу добавить еще одно приложение nodejs, которое обычно работает на порте 3000 и использует обратный прокси-сервер на Nginx от порта 8000 до 3000. Но получается, что шлюз 502 плох. Вот мой статус pm2

┌──────────┬────┬─────────┬──────┬───────┬────────┬─────────┬────────┬─────┬───────────┬──────┬──────────┐
│ 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

Я подозреваю, что настоящая причина 502 состоит в том, что пользователь является пользователем root, поэтому я изменяю все свои js-файлы на

-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

Я выставил порт 8000 на firewall-cmd, а также добавил его к /etc/service. Но все это не удалось.

Вот значение по умолчанию для nginx (/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(/|$) {
                # include fastcgi.conf;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
        if (!-f $document_root$fastcgi_script_name) {
                return 404;
        }
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
                include fastcgi_params;
        # fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }

# 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 {
#        }
#    }

}

Для вашего сведения, для этого VPS еще не задано доменное имя. Так что все это работает на обычном http.

А вот и конф для 8000 порта

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;

    }
}

В большинстве решений показано, как запустить pm2 и nginx в Ubuntu, но не так много о Centos 7. Что вы думаете?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...