簡體   English   中英

在 Nginx 中使用代理傳遞時,Nodejs 上的“無法獲取”

[英]'Cannot GET' on Nodejs when using proxy pass in Nginx

我在 Jelastic Paas 上運行 Nginx 和 NodeJS,需要一個 Nginx 反向代理來定向到 Nodejs 上的 React 應用程序。

我收到“無法獲取/”錯誤消息,並且不確定它是在 Nginx 還是 nodejs 端,我在其他環境中做了相同的配置,沒有任何問題。

問題:

  1. 有什么我忘記了嗎?
  2. 以下配置是否正確?

http {

server_tokens off ;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

        set_real_ip_from  <PRIVATE IP>;
        set_real_ip_from  <PRIVATE IP>;
        set_real_ip_from  <PRIVATE IP>;
        real_ip_header    X-Forwarded-For;
        real_ip_recursive on;

    log_format  main  '$remote_addr:$http_x_remote_port - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for" '
                      '"$host" sn="$server_name" '
                      'rt=$request_time '
                      'ua="$upstream_addr" us="$upstream_status" '
                      'ut="$upstream_response_time" ul="$upstream_response_length" '
                      'cs=$upstream_cache_status' ;

        client_header_timeout 10m;
        client_body_timeout 10m;
        send_timeout 10m;
        client_max_body_size 100m;

        connection_pool_size 256;
        client_header_buffer_size 1k;
        large_client_header_buffers 4 2k;
        request_pool_size 4k;

        gzip_min_length 1100;
    gzip_buffers 4 8k;
    gzip_types text/plain;

    output_buffers 1 32k;
    postpone_output 1460;

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;

    keepalive_timeout 75 20;

    ignore_invalid_headers on;

map $upstream_addr        $group {
    default               "";

.<PRIVATE IP>:80$ common;
    }

    upstream default_upstream{
server <PRIVATE IP>;
    sticky path=/; keepalive 100;
}

upstream common {   server <PRIVATE IP> ;  sticky path=/; keepalive 100; }

        server {
            listen *:80;
            listen [::]:80;
            server_name  _;

            access_log /var/log/nginx/localhost.access_log main;
            error_log /var/log/nginx/localhost.error_log info;

                proxy_temp_path /var/nginx/tmp/;
            proxy_connect_timeout 5s;

            error_page   500 502 503 504  /50x.html;

            proxy_next_upstream error timeout http_500;
            proxy_http_version 1.1;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Host $http_host;
            proxy_set_header X-Forwarded-For $http_x_forwarded_for;
            proxy_set_header X-Remote-Port $http_x_remote_port;
            proxy_set_header X-URI $uri;
            proxy_set_header X-ARGS $args;
            proxy_set_header Refer $http_refer;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            if ($http_x_remote_port = '' ) {
                set $http_x_remote_port $remote_port;
            }
  
            location = /50x.html {
                    root   html;
            }

            location / {
                    if ($cookie_SRVGROUP ~ group|common) {
                            proxy_pass http://$cookie_SRVGROUP;
                            error_page   500 502 503 504 = @rescue;
                    }

                    if ($cookie_SRVGROUP !~ group|common) {
                            add_header Set-Cookie "SRVGROUP=$group; path=/";
                    }
                    proxy_pass http://default_upstream;
                    add_header Set-Cookie "SRVGROUP=$group; path=/";
            }

            location @rescue {
                    proxy_pass http://default_upstream;
                    add_header Set-Cookie "SRVGROUP=$group; path=/";
            }

        }

 include /etc/nginx/conf.d/*.conf;

}

這是我收到的消息

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM