【问题标题】:nginx proxy too slownginx代理太慢了
【发布时间】:2016-06-05 06:40:24
【问题描述】:

我有一个 nginx 服务器部署在 GoDaddy XLarge 云服务器中,具有 8GB RAM 和 4 个 CPU。我对 nginx 的设置是将请求代理到 Google App Engine 应用程序。

问题是 nginx 提供静态文件的速度太慢,有时会中断连接,呈现网站完整或损坏的图像、CSS 和 JS 文件。现在直接访问 GAE 应用程序,静态文件的服务速度非常快。

这是我的服务器 nginx.conf 文件:

user www-data;
worker_processes 1;
worker_rlimit_nofile    20480; # worker_connections * 4
pid /run/nginx.pid;

events {
    use epoll;
    worker_connections 4096;
    multi_accept on;
}

http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    client_body_timeout 12;
    client_header_timeout 12;
    keepalive_timeout 15;
    send_timeout 10;
    types_hash_max_size 2048;
    # server_tokens off;

    ## 
    # Tweaks
    # https://www.digitalocean.com/community/tutorials/how-to-optimize-nginx-configuration
    ##

    client_body_buffer_size 10K;
    client_header_buffer_size 1k;
    client_max_body_size 8m;
    large_client_header_buffers 2 1k;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ##
    # 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_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

    ## 
    ## Proxy Settings
    ##
    proxy_buffering off;

    ##
    # nginx-naxsi config
    ##
    # Uncomment it if you installed nginx-naxsi
    ##

    #include /etc/nginx/naxsi_core.rules;

    ##
    # nginx-passenger config
    ##
    # Uncomment it if you installed nginx-passenger
    ##

    #passenger_root /usr;
    #passenger_ruby /usr/bin/ruby;

    ##
    # Virtual Host Configs
    ##

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

更新

这里是应用服务器的网络图:

这里是 NGINX 服务器的网络图(非常慢)

  • 什么可能导致此配置中的 nginx 运行缓慢?
  • 这是因为 GoDaddy 云服务器速度慢吗?还是 NGINX 配置真的有问题?
  • 什么配置可以让代理快速工作?

【问题讨论】:

  • 显示服务器块配置和错误日志
  • /var/log/nginx/error.log 为空
  • 您可以将工作进程设置为 4 而不是 1。它通常等于您的 CPU 拥有的核心数。

标签: google-app-engine nginx


【解决方案1】:

尝试优化这些:

1.worker process 因为你有一个 4 核 CPU 并且你在一个请求中提供了相当多的文件,所以它的值应该至少是 4,或者这个值

grep processor /proc/cpuinfo | wc -l

2.常用js文件使用CDN。

我看到您使用 GAE 直接提供的一些通用库(jquery-1.10.2.min.js、Angular-1.4.3.js、fontawesome-webfont.wotf2 等)。这些文件需要几秒钟才能加载。您应该尝试通过 CDN 来提供这些文件。

3.用Google PageSpeed Tools做一个测试,很有帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-11
    • 1970-01-01
    • 1970-01-01
    • 2016-02-14
    • 2018-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多