首页 > 解决方案 > 从 NGINX Web 服务器加载 React 静态文件的问题

问题描述

NGINX Web 服务器大约需要 3 分钟来加载一个大约 3MB 的 React 静态文件。并且下载加载应用程序的性能很慢

我尝试在我的 React 文件上压缩静态文件

这是我在 NGINX 中的当前配置

upstream app1{
    # Use ip_hash algo for session affinity
    least_conn;
    server 192.168.1.7:3000;
    server 192.168.3.7:3000;
}
location /app1 {
        # Force timeouts if the backend dies
        #proxy_next_upstream error timeout invalid_header http_500 http_502 http_503;

        # Set timeouts
        proxy_connect_timeout  3600;
        proxy_send_timeout     3600;
        proxy_read_timeout     3600;
        send_timeout           3600;

        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";

        proxy_redirect off;
        proxy_set_header Host $http_host;
        proxy_set_header X-Forwarded-Host $http_host;
        #proxy_set_header X-Forwarded-Proto $scheme;
        proxy_pass https://app1/;

        proxy_buffering         off;
    }
location ~* ^/static {
        proxy_pass https://app1$request_uri;
        proxy_buffering         off;
    }
location ~ ^/build {
        proxy_pass https://app1$request_uri;
    }

我希望能够在 NGINX 服务器中提供静态内容,而无需从应用程序服务器获取。我还希望能够将文件压缩到最小大小,例如 10 KB。

标签: nginxpm2nginx-locationnginx-reverse-proxynginx-config

解决方案


推荐阅读