Nginx拒绝连接

时间:2019-03-31 08:04:11

标签: node.js nginx digital-ocean

我在由Nginx和Express驱动的Droplet中设置了一个nodejs应用程序。 REST API在本地运行时运行良好。即使在服务器内部,我也可以向test.domain.com/api发出CURL请求,并返回数据。但是我无法让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


}

}

我已经检查了错误和访问日志。我在那里看不到任何可疑的东西。这是我第一次设置服务器,任何帮助将不胜感激。谢谢!

编辑:The error logs The access logs

0 个答案:

没有答案