0

I'm running Nginx & NodeJS on Jelastic Paas, and need a Nginx reverse proxy to direct to a React app on a Nodejs.

I'm getting a "Cannot get/" error message, and not sure if it's on the Nginx or nodejs side, I did the same configuration on an other environment without any problem.

Question:

  1. Is there something I'm forgetting?
  2. Is the following configuration correct?

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;

}
  • 1
    what does your route look like. 'Cannont get' is a node error message so it looks like its getting to your route, otherwise I would expect an nginx error message. Do you have a screenshot of the error message, would probably help in determining where the message is coming from – proxim0 Jul 21 '21 at 14:27
  • Thank you for confirming that nginx is indeed communicating with nodejs, message i'm getting is just a "Cannot GET /" – Guillaume Lauzier Jul 21 '21 at 14:37
  • I added the screenshot in the answers – Guillaume Lauzier Jul 21 '21 at 14:39

1 Answers1

0

Here is the message I'm getting

enter image description here

  • 1
    Thats for sure a node message, its basically saying I don't have a route for that, what does your route look like? Also on the node app you could add some error handling to ensure traffic is getting sent to node, just cant find the route, hence the 'cannot GET /' error message – proxim0 Jul 21 '21 at 14:52
  • Thank you Prox, now I need to focus on the Nodejs side. Seems the npm run build command and Create react app method doesn't work so good. – Guillaume Lauzier Jul 22 '21 at 14:49