У меня есть приложение nodejs, созданное в виде капли, работающей на Nginx и Express.API REST работают нормально при локальном запуске.Даже изнутри сервера я могу сделать запрос CURL к test.domain.com/api, и он вернет данные.Но я не могу заставить API работать внешне.Когда я пытаюсь curl -v test.domain.com/api
, я получаю
* Trying 159.65.158.66...
* TCP_NODELAY set
* Connection failed
* connect to 159.65.158.66 port 443 failed: Connection refused
* Failed to connect to test.domain.com port 443: Connection refused
* Closing connection 0
curl: (7) Failed to connect to test.domain.com port 443: Connection refused
Эта ошибка произошла с отключенным брандмауэром на сервере.Попытка HTTP выдает ту же ошибку, хотя и с портом 80. Попытка netstat -punta | grep 443
показывает
tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 7285/nginx: master
Я проверил, чтобы убедиться, что символические ссылки между включенными и доступными сайтами тоже верны.
Вот test.domain.com с включенных сайтов
server {
server_name test.domain.com; # managed by Certbot
listen [::]:443 ssl; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/test.domain.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/test.domain.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
location /
return 200 'Here I am!';{
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://localhost:8080/;
proxy_ssl_session_reuse off;
proxy_set_header Host $http_host;
proxy_cache_bypass $http_upgrade;
proxy_redirect off;
}
}
server {
if ($host = test.domain.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
listen [::]:80;
server_name test.domain.com;
return 404; # managed by Certbot
}
}
А вот мой nginx.conf
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
server_tokens off;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
server { # simple reverse-proxy
server_name test.domain.com;# pass requests for dynamic content to rails/turbogears/zope, et al
location / {
proxy_pass http://localhost:8080;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/test.domain.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/test.domain.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
map $sent_http_content_type $expires {
default off;
text/html 0;
text/css 0;
application/javascript 0;
~image/ 0;
}
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
#include /etc/nginx/sites-enabled/*;
server {
if ($host = test.domain.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 81;
server_name test.domain.com;
return 404; # managed by Certbot
}
}
Я проверил ошибку и доступжурналы.Я не вижу ничего подозрительного там.Я впервые настраиваю сервер, и любая помощь будет признательна.Спасибо!
РЕДАКТИРОВАТЬ: