The speed of nginx reverse proxy to native nodejs application is very slow.

I built a website with nodejs, but other machines on the same network could not access it. I checked on the Internet, and some people said that I needed a web server to publish it, so I took nginx to reverse proxy to my nodejs, but it was very slow. You have to wait a long time for every first visit. But direct access to the nodejs port is fast. The project is very small and should not be, so I feel that the reverse proxy is not set up correctly. Solve?

-sharpuser  nobody;
worker_processes 2;

-sharperror_log  logs/error.log;
-sharperror_log  logs/error.log  notice;
error_log  logs/error.log  info;

-sharppid        logs/nginx.pid;


events {
    worker_connections  65535;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    server_names_hash_bucket_size 128;   -sharp
    client_header_buffer_size 32k;       -sharp
    large_client_header_buffers 4 32k;   -sharp
    client_max_body_size 300m;           -sharp
    tcp_nopush     on;      -sharpon
    keepalive_timeout  60;  -sharp60
    tcp_nodelay on;        -sharp
    server_tokens off;     -sharpnginx
    gzip  on;  -sharpon
    gzip_min_length  1k;      -sharp
    gzip_buffers     4 16k;   -sharp
    gzip_http_version 1.1;    -sharp
    gzip_comp_level 2;        -sharp
    gzip_types       text/plain application/x-javascript text/css application/xml;  -sharp
    gzip_vary on;  -sharp
    -sharplog_format  main  "$remote_addr - $remote_user [$time_local] "$request" "
    -sharp                  "$status $body_bytes_sent "$http_referer" "
    -sharp                  ""$http_user_agent" "$http_x_forwarded_for"";

    -sharpaccess_log  logs/access.log  main;

    sendfile        on;
    -sharptcp_nopush     on;

    -sharpkeepalive_timeout  0;
    -sharpkeepalive_timeout  65;

    -sharpgzip  on;
     map $http_upgrade $connection_upgrade {
        default upgrade;
        ""      close;
    }

    server {
        listen       9080;
        server_name  localhost;

        -sharpcharset koi8-r;

        -sharpaccess_log  logs/host.access.log  main;

        -sharplocation / {
         -sharp   root   html;
         -sharp   index  index.html index.htm;
        -sharp}
        location / {
            proxy_pass http://localhost:8080; -sharpnodejs 
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            -sharptime out settings
            proxy_connect_timeout 159s;
            proxy_send_timeout   600;
            proxy_read_timeout   600;
            proxy_buffer_size    64k;
            proxy_buffers     16 32k;
            proxy_busy_buffers_size 64k;
            proxy_temp_file_write_size 64k;
            proxy_pass_header Set-Cookie;
            proxy_redirect     off;
            proxy_hide_header  Vary;
            proxy_set_header   Accept-Encoding "";
            proxy_ignore_headers Cache-Control Expires;
            proxy_set_header   Referer $http_referer;
            proxy_set_header   Host   $host;
            proxy_set_header   Cookie $http_cookie;
            proxy_set_header   X-Real-IP  $remote_addr;
            proxy_set_header X-Forwarded-Host $host;
            proxy_set_header X-Forwarded-Server $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }

        -sharperror_page  404              /404.html;

        -sharp redirect server error pages to the static page /50x.html
        -sharp
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        -sharp proxy the PHP scripts to Apache listening on 127.0.0.1:80
        -sharp
        -sharplocation ~ \.php$ {
        -sharp    proxy_pass   http://127.0.0.1;
        -sharp}

        -sharp pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        -sharp
        -sharplocation ~ \.php$ {
        -sharp    root           html;
        -sharp    fastcgi_pass   127.0.0.1:9000;
        -sharp    fastcgi_index  index.php;
        -sharp    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        -sharp    include        fastcgi_params;
        -sharp}

        -sharp deny access to .htaccess files, if Apache"s document root
        -sharp concurs with nginx"s one
        -sharp
        -sharplocation ~ /\.ht {
        -sharp    deny  all;
        -sharp}
    }


    -sharp another virtual host using mix of IP-, name-, and port-based configuration
    -sharp
    -sharpserver {
    -sharp    listen       8000;
    -sharp    listen       somename:8080;
    -sharp    server_name  somename  alias  another.alias;

    -sharp    location / {
    -sharp        root   html;
    -sharp        index  index.html index.htm;
    -sharp    }
    -sharp}


    -sharp HTTPS server
    -sharp
    -sharpserver {
    -sharp    listen       443;
    -sharp    server_name  localhost;

    -sharp    ssl                  on;
    -sharp    ssl_certificate      cert.pem;
    -sharp    ssl_certificate_key  cert.key;

    -sharp    ssl_session_timeout  5m;

    -sharp    ssl_protocols  SSLv2 SSLv3 TLSv1;
    -sharp    ssl_ciphers  HIGH:!aNULL:!MD5;
    -sharp    ssl_prefer_server_ciphers   on;

    -sharp    location / {
    -sharp        root   html;
    -sharp        index  index.html index.htm;
    -sharp    }
    -sharp}

}
Sep.01,2021

what are you doing with so many HTTP header settings with nginx?

only these three are needed, and the others are deleted:

proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

delete this paragraph, too:

map $http_upgrade $connection_upgrade {
    default upgrade;
    ''      close;
}

it's likely that you set up upgrade's header to cause the problem.


add the following configuration items under server to see if it works

ip_hash;

have you solved this problem? I also encountered


https://github.com/lizeze/not.

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e48205-4323d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e48205-4323d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?