我使用nginx有两个目的,第一个是代理传递请求,第二个是使用ip2位置模块。现在我想优化nginx以实现我的目的。问题是,当我使用nginx时出于这些原因,我的每秒吞吐量降低到接近一半左右。任何建议都会受到关注,并提前感谢。
content of nginx.conf
user nginx nginx;
worker_processes 2;
worker_rlimit_nofile 30000;
#worker_rlimit_nofile 200000;
worker_cpu_affinity 0001 0010;
error_log /var/log/nginx/error.log crit;
pid /var/run/nginx.pid;
events {
worker_connections 2048;
}
http {
upstream default {
server 127.0.0.1:8000;
}
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=one:8m max_size=3000m inactive=600m;
include /etc/nginx/mime.types;
default_type application/octet-stream;
real_ip_header X-Forwarded-For;
set_real_ip_from 0.0.0.0/0;
ip2location on;
ip2location_database /data/geo/ip2location/DATA.BIN;
ip2location_access_type shared_memory;
include /etc/nginx/conf-other/timezone.conf;
include /etc/nginx/conf-other/timezone-offset.conf;
variables_hash_max_size 2048;
variables_hash_bucket_size 512;
proxy_headers_hash_max_size 2048;
proxy_headers_hash_bucket_size 512;
types_hash_bucket_size 512;
server_names_hash_bucket_size 512;
server_names_hash_max_size 8192;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" "$proxy_add_x_forwarded_for" "$scheme"';
access_log /dev/null;
server_tokens off;
sendfile on;
tcp_nopush on;
keepalive_timeout 65;
keepalive_requests 100000;
include /etc/nginx/conf.d/*.conf;
gzip on;
gzip_comp_level 6;
gzip_vary on;
gzip_min_length 1000;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
gzip_buffers 16 8k;
client_body_buffer_size 10K;
client_header_buffer_size 1k;
client_max_body_size 8m;
large_client_header_buffers 2 1k;
client_body_timeout 12;
client_header_timeout 12;
send_timeout 10;
}
content of /cong.d/virtual.conf
server {
listen 80;
server_name localhost;
#access_log off; //Uncommit for Production
more_set_headers 'Server: rey-dmp.com';
error_page 404 /404.html;
location = /404.html {
root /var/www/default;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/default;
}
location = /index.html {
root /var/www/default;
}
location = /favicon.ico {
expires 365d;
proxy_cache_key $uri;
root /var/www/public/images;
}
location /images/ {
#autoindex on;
expires 1d;
proxy_cache_key $uri;
root /var/www/public;
try_files $uri /images/default.gif;
}
location /js/ {
#autoindex on;
expires 1d;
proxy_cache_key $uri;
root /var/www/dmp/public/javascripts;
try_files $uri /images/default.gif;
}
location / {
proxy_pass http://127.0.0.1:XXXX/;
proxy_pass_header Server;
proxy_redirect off;
proxy_set_header REMOTE_ADDR $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Scheme $scheme;
proxy_hide_header X-Powered-By;
proxy_set_header X-Referer $http_referer;
proxy_set_header IP2LOCATION_COUNTRY_LONG $ip2location_country_long;
proxy_set_header IP2LOCATION_REGION $ip2location_region;
proxy_set_header IP2LOCATION_CITY $ip2location_city;
}
}