回答问题

我们使用 NGINX 作为反向代理来集成到网站。所有请求都将根据 url 转发到一个网站或另一个网站。由于额外的“跃点”,我们本来预计会出现小的性能损失,但性能确实很差。每个资源加载 css、js 和图像需要 1-2 秒。 NGINX 服务器的 CPU 负载 <1%。

如果我使用 Firebug 进行调查,我会在 Net 面板中看到巨大的阻塞和等待时间:通过 NGINX 作为反向代理的性能

如果我们直接去原始网站,它会快得多(~100 ms):在此处输入图像描述

这种“节流”的原因可能是什么?

这是我的网站配置:

    server {
        listen 80;
        server_name *.mysite.nl;
        return 301 http://www.mysite.nl$request_uri;
}

server {
    listen 80;
    root /var/www/;
    index index.php index.html index.htm index.asp index.aspx;
    server_name www.mysite.nl;
    return 301 https://$server_name$request_uri;
    include includes/mysite.nl-redirects.conf;

    location / {
    return 301 https://$server_name$request_uri;
    proxy_set_header X-Real-IP  $remote_addr;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header Host $host;
    proxy_pass http://100.6.185.172:80;
    proxy_set_header        X-Forwarded-Proto "http";
    }
    location /account {

    proxy_set_header X-Real-IP  $remote_addr;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header Host $host;
    proxy_pass http://platform.mysite.nl:80;
    }
    location /contentowner {
    proxy_set_header X-Real-IP  $remote_addr;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header Host $host;
    proxy_pass http://platform.mysite.nl:80;
    }
}

server {
        listen   443;
        root /var/www/;
        index index.php index.html index.htm index.asp index.aspx;
        server_name www.mysite.nl;
        ssl_certificate           /etc/ssl/private/mysite.nl/cert.crt;
        ssl_certificate_key       /etc/ssl/private/mysite.nl/cert.key;
        ssl_client_certificate    /etc/ssl/private/mysite.nl/ca.crt;
        ssl on;
        ssl_session_cache  builtin:1000  shared:SSL:10m;
        ssl_protocols  TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;
        ssl_prefer_server_ciphers on;

    include includes/mysite.nl-redirects.conf;

        location / {
        proxy_set_header        X-Forwarded-Proto "https";
        proxy_set_header X-Real-IP  $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Host $host;
        proxy_pass https://100.6.185.172:443;
        }
        location /account/ {
        #return 301 http://$server_name$request_uri;
        proxy_set_header        X-Forwarded-Proto "https";
        proxy_set_header X-Real-IP  $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Host $host;
        proxy_pass http://platform.mysite.nl:80;
        }
        location /contentowner/ {
        #return 301 http://$server_name$request_uri;
        proxy_set_header        X-Forwarded-Proto "https";
        proxy_set_header X-Real-IP  $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Host $host;
        proxy_pass http://platform.mysite.nl:80;
        }
}

这是我的 nginx.config:

    user www-data;
worker_processes auto;
pid /run/nginx.pid;

events {
        worker_connections 18000;
        multi_accept on;
}

http {

        ##
        # Basic Settings
        ##

        sendfile on;
        tcp_nopush off;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        server_tokens off;
        client_max_body_size 5M;
        #proxy_buffering off;
        #access_log 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_dhparam /etc/nginx/ssl/dhparam.pem;
        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_disable "msie6";

        gzip_vary on;
        gzip_proxied any;
        gzip_comp_level 6;
        gzip_buffers 16 8k;
        gzip_http_version 1.1;
        gzip_min_length 256;
        gzip_types text/plain text/css application/json application/x-javascript application/javascript text/xml application/xml application$

        ##
        # Virtual Host Configs
        ##

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

Answers

您在原始服务器上使用 HTTP/2,但不在反向代理上。看到您的页面正在加载的其他资源的数量,这至少是问题的一部分。

Logo

开发云社区提供前沿行业资讯和优质的学习知识,同时提供优质稳定、价格优惠的云主机、数据库、网络、云储存等云服务产品

更多推荐