首页 > 系统相关 >nginx高并发优化之模板

nginx高并发优化之模板

时间:2022-12-21 17:31:09浏览次数:35  
标签:http 并发 cache header nginx proxy timeout gzip 模板

下面的Nginx.conf实现nginx在前端做反向代理服务器的完整配置文件的例子,处理js、png等静态文件,jsp/php等动态请求转发到其它服务器tomcat/apache
user www www;
worker_processes auto;
worker_cpu_affinity auto;
error_log logs/error.log;
worker_rlimit_nofile 102400;
pid logs/nginx.pid;
events {
use epoll;
worker_connections 102400;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"'
'"$upstream_cache_status"';
access_log logs/access.log main;
server_tokens off;
sendfile on;
tcp_nopush on;
keepalive_timeout 65;
#Compression Settings
gzip on;
gzip_comp_level 6;
gzip_http_version 1.1;
gzip_proxied any;
gzip_min_length 1k;
gzip_buffers 16 8k;
gzip_types text/plain text/css text/javascript application/json application/javascript application/x-javascript application/xml;
gzip_vary on;
#end gzip
# http_proxy Settings
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 75;
proxy_send_timeout 75;
proxy_read_timeout 75;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
proxy_buffering on;
proxy_temp_path /usr/local/nginx1.10/proxy_temp;
proxy_cache_path /usr/local/nginx1.10/proxy_cache levels=1:2 keys_zone=my-cache:100m max_size=1000m inactive=600m max_size=2g;
#load balance Settings
upstream backend {
hash $remote_addr consistent;
server 192.168.31.141:80 weight=1 max_fails=2 fail_timeout=10s;
server 192.168.31.250:80 weight=1 max_fails=2 fail_timeout=10s;
}
#virtual host Settings
server {
listen 80;
server_name localhost;
charset utf-8;
location ~/purge(/.*) {
allow 127.0.0.1;
allow 192.168.31.0/24;
deny all;
proxy_cache_purge my-cache $host$1$is_args$args;
}
location / {
index index.php index.html index.htm;
proxy_pass http://backend;
proxy_redirect off;
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_ignore_headers Set-Cookie;
proxy_hide_header Set-Cookie;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
}
location ~ .*\.(gif|jpg|png|html|htm|css|js|ico|swf|pdf)(.*) {
proxy_pass http://backend;
proxy_redirect off;
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_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_cache my-cache;
add_header Nginx-Cache $upstream_cache_status;
proxy_cache_valid 200 304 301 302 8h;
proxy_cache_valid 404 1m;
proxy_cache_valid any 1d;
proxy_cache_key $host$uri$is_args$args;
expires 30d;
access_log off;
}
location /nginx_status {
stub_status on;
access_log off;
allow 192.168.31.0/24;
deny all;
}
}
}

$upstream_cache_status这个变量来显示缓存的状态,我们可以在配置中添加一个http头来显示这一状态,
$upstream_cache_status包含以下几种状态:
·MISS 未命中,请求被传送到后端
·HIT 缓存命中
·EXPIRED 缓存已经过期请求被传送到后端
·UPDATING 正在更新缓存,将使用旧的应答
·STALE 后端将得到过期的应答
expires : 在响应头里设置Expires:或Cache-Control:max-age,返回给客户端的浏览器缓存失效时间。

标签:http,并发,cache,header,nginx,proxy,timeout,gzip,模板
From: https://blog.51cto.com/u_13236892/5960029

相关文章

  • EBS:BI Publisher模板文件查询
    BIPublisher模板文件查询 --N:OracleXMLPublisher>>主页>>模板SELECTXT.TEMPLATE_ID,XT.TEMPLATE_NAMEAS"模板-名称",XT.TEMPLATE_CODEAS"......
  • openssl jni nginx证书私钥有效性校验
     1、安装opensslwgethttps://www.openssl.org/source/openssl-1.1.1b.tar.gz./config--prefix=/usr/local/openssl --shared--shared为添加动态库,生成libssl.so,默......
  • 基于Go语言实现高并发推荐系统架构设计
    你好!我是封幼林,在小年糕负责推荐系统,主要从事服务架构相关工作。今天我要和你分享的话题是《高并发推荐系统架构设计》。这次分享主要分为以下这几个部分:推荐系统的基......
  • go通过chan和go func进行并发控制
    原文:Go并发实战核心编程【一】1.需求启动一个goroutine,将1-10000的数字放入chan中启动4个goroutine从chan中读取数字,并计算是不是素数是素数就讲结果放入结果chan......
  • nginx 拦截访问敏感信息文件
    背景安全部门在做渗透测试的时候发现前端项目可以直接访问config.js文件,里面的配置信息都可以直接被查看到,要求要将敏感信息屏蔽。这里面有三个方法:1、将config.js文件在打......
  • Web集群案例实战 -- Nginx 反向代理 -- 案例实战
    Nginx反向代理--案例实战​​前言​​前言本环境是基于Centos7.8系统构建Nginx学习环境具体构建,请参考​​Nginx-1.18.0环境部署​​环境准备rolehostipnginx-vers......
  • Web集群案例实战 -- Nginx 负载均衡 -- 案例实战
    Nginx负载均衡--案例实战​​前言​​前言本环境是基于Centos7.8系统构建Nginx学习环境具体构建,请参考​​Nginx-1.18.0环境部署​​环境准备rolehostipnginx-vers......
  • Web集群案例实战 -- Nginx 负载均衡 之 客户端访问日志优化
    Nginx负载均衡之客户端访问日志优化​​前言​​前言本环境是基于Centos7.8系统构建Nginx学习环境具体构建,请参考​​Nginx-1.18.0环境部署​​Nginx在做反向代理......
  • 30秒在Centos7安装Nginx(步骤简单)
    Nginx安装1、安装好依赖gcc、gcc-c++、pcre-devel、zlib-devel、openssl、openssl-devel、wgetyum-yinstallgccpcre-develzlib-developensslopenssl-develgcc-c++w......
  • 高并发架构设计经验总结
      高并发解决的核心问题是在同一时间上有大量的请求过来,然后我们的系统要怎么抗住这些请求带来的压力。本文从基础设施层、服务端架构层、服务应用层分别做了一个简单......