上传文件时出现 502 Bad Gateway(NGINX 和 NodeJS)

上传文件时出现 502 Bad Gateway(NGINX 和 NodeJS)

我正在开发一款可供用户上传文件的应用程序。虽然后端调用似乎运行正常,但上传文件时的调用返回 502 Bad Gateway 消息。

文件确实上传了,但出现了错误消息。我认为这与我的 nginx 配置有关,所以我希望你们能指出我哪里出错了。

以下是 nginx 错误日志消息

[error] 3807#3807: *138 connect() failed (111: Connection refused) while connecting to upstream, client: 189.62.45.133, server: api-dev.app.com.br, request: "GET /users/pics/5218de9eec94a7bb4467c95219b37b41ec1920420c808d9e11244f8d2a234cd6 HTTP/1.1", upstream: "https://161.35.116.108:2000/users/pics/5218de9eec94a7bb4467c95219b37b41ec1920420c808d9e11244f8d2a234cd6", host: "api-dev.app.com.br", referrer: "https://dev.app.com.br/profile"

这是我的 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
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    client_max_body_size 100M;
    # 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;

    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

我的 conf.d 文件夹是空的,但是我在 sites-enabled 中确实有特定的设置。

这是我的app.com.br.conf:

proxy_cache_path  /etc/nginx/cache levels=1:2 keys_zone=nuxt-cache:25m max_size=1g inactive=60m use_temp_path=off;

server {
    listen 80;
    listen [::]:80;
    server_name dev.app.com.br api-dev.app.com.br;
    return 301 https://$server_name$request_uri;
}

server {
    server_name dev.app.com.br;
    index index.html;

    root /opt/siena/App-Web-Nuxt/dist;

    listen [::]:443 ssl ipv6only=on;
    listen 443 ssl;
    ssl_certificate /etc/letsencrypt/live/dev.app.com.br-0001/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/dev.app.com.br-0001/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

    location / {
        try_files $uri $uri/index.html $uri.html;
    }

}


server {
    server_name api-dev.app.com.br;

    listen [::]:443 ssl;
    listen 443 ssl;
    ssl_certificate /etc/letsencrypt/live/api-dev.app.com.br/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/api-dev.app.com.br/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

    location / {
        # more_set_headers 'Access-Control-Allow-Origin: *';
        # more_set_headers 'Access-Control-Allow-Methods: GET,POST,OPTIONS,DELETE,PUT';
        # more_set_headers 'Access-Control-Allow-Headers:DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';

        # Simple requests (simples to fix CORS)
        if ($request_method ~* "(GET|POST)") {
            more_set_headers "Access-Control-Allow-Origin:  *";
        }

        # Preflighted requests
        if ($request_method = OPTIONS ) {
            more_set_headers "Access-Control-Allow-Origin:  *";
            more_set_headers "Access-Control-Allow-Methods: GET, POST, OPTIONS, HEAD";
            more_set_headers "Access-Control-Allow-Headers: Authorization, Origin, X-Requested-With, Content-Type, Accept";
            return 204;
        }

        proxy_read_timeout 300s;
        proxy_connect_timeout 75s;
        proxy_redirect off;
        proxy_pass https://161.35.116.108:2000/;
    }
}

如果对系统和配置还有其他问题,请告诉我。

提前致谢。

相关内容