【发布时间】: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 拥有的核心数。