Question
Проблема с прокси nginx с node js приложением
Опишу вам поэтапно, как настраиваю сервер
1)Делаю дроплет на Centos 8
2)Вхожу в систему и меняю пароль
3)Создаю нового юзера и задаю пароль
adduser shmzl
passwd shmzl
4)Даю ему привилегию sudo
gpasswd -a shmzl wheel
5)dnf update and dnf uprage
6)Отключаю на время SElinux
7)установка и настройка firewalld
dnf install firewalld -y
systemctl start firewalld
firewall-cmd –permanent –add-service=(http, http, mysql, openvpn)
firewall-cmd –reload (пока что его выключил)
8)Настройка подключению по публичному ключу и дублировании директории ssh пользователю shmzl
9)Захожу от имени пользователя shmzl
10)активирую веб консоль
systemctl enable –now cockpit.socket
11)закрываю доступ по паролю
12)устанавливаю node js
sudo dnf clean all
sudo dnf makecache fast (пишет, что неправильный аргумент fast, я делал, как в гайде расписано)
sudo dnf install -y gcc-c++ make
sudo dnf install nodejs
13)создаю папку, пушу проект
14)ставлю pm2
sudo npm install pm2@latest -g
15)Ставлю nginx
sudo dnf install nginx
16)настраиваю файл nginx conf
(скину текстом его после этого сообщения)
sudo systemctl restart nginx
17) Создаю группу WebAdmin, включаю туда пользователя и nginx
18) создаю папку /var/www и кидаю туда проект, делаю разрешению права на эту папку
mkdir /var/www
tar -xvf cd…gz -C /var/www
19)устанавливаю mysql, создаю базу test
20)захожу в папку с проектом
npm install
./node..../dbmigrate up
pm2 start app.js
21)так же я закинул стринцы ошибок в папку с проектом
Перехожу по своему домену и nginx страницу ошибки (вот ссылка, если что http://test.trinbox.ru )
Вот мой nginx.config
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/doc/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;
server {
listen 80 default_server;
server_name test.trinbox.ru;
root /var/www/cd-test;
location / {
proxy_read_timeout 5m;
proxy_pass http://localhost:3000;
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;
}
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 PROFILE=SYSTEM;
# 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 {
# }
# }
}
Локально все запускается.
Вот еще error log nginx
2020/12/20 17:53:13 [error] 6496#0: *17 connect() failed (111: Connection refused) while connecting to upstream, client: 176.59.97.233, server: test.trinbox.ru, request: "GET / HTTP/1.1", upstream: "http://[::1]:3000/", host: "test.trinbox.ru" 2020/12/20 17:53:13 [error] 6496#0: *17 connect() failed (111: Connection refused) while connecting to upstream, client: 176.59.97.233, server: test.trinbox.ru, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:3000/", host: "test.trinbox.ru"
Почему два errora почти одинаковых в одно время? В папке есть еще nginx.conf.default, это может как связано?
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
×
Когда запускаю приложение через npm start app.js , то при команде curl http://localhost:3000 все работает, как надо, а через pm2 он пишет curl: (7) Failed to connect to localhost port 3000: Connection refused