NGINX作为反向代理减慢了网站的速度

时间:2016-11-23 10:29:42

标签: http nginx reverse-proxy

我们使用NGINX作为反向代理来集成到网站。所有请求都会根据网址转发到一个网站或另一个网站。由于额外的“啤酒花”,我们预计会有少量的性能损失。但表现非常糟糕。每个资源加载css,js和图像需要1-2秒。 NGINX服务器的CPU负载<1%。

如果我使用Firebug进行调查,我会在Net面板中看到巨大的阻止和等待时间:Performance via NGINX as reverse proxy

如果我们直接去原始网站,它会快得多(~100毫秒): enter image description here

这可能是什么原因导致了这种情况?&#39;

这是我的网站配置:

    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/*;
}

1 个答案:

答案 0 :(得分:1)

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