@dooy
2022-12-19T08:09:31.000000Z
字数 2934
阅读 321
Nginx
很多时候我们以为 gzip on; 就以为都会压缩了,其实他只压缩了html 或者php输出是html;而对于css js 图片等都没有压缩。 如何配置 css js 图片都压缩了
gzip on;gzip_min_length 1k;gzip_buffers 4 16k;gzip_comp_level 2;gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png application/javascript; #根据header来压缩gzip_vary on;gzip_disable "MSIE [1-6]\."; #ie 不压缩
在 http{} 中加入
proxy_temp_path pigai_cache 1 2;proxy_cache_path pigai_cache/pigai levels=1:2 keys_zone=pigai:100m inactive=1d max_size=10g;
在你加的server{} 中加入
location ~ .*\.(js|css|gif|jpg|jpeg|png|bmp|swf|flv)${proxy_pass http://pigai;expires 6h; #设置浏览器过期时间proxy_cache pigai;#使用pigai这个keys_zoneproxy_cache_key $host$uri$is_args$args;proxy_cache_valid 200 302 1h;#200和302状态码保存1小时proxy_cache_valid 301 1d;#301状态码保存一天proxy_cache_valid any 1m;#其它的保存一分钟add_header X-Cache $upstream_cache_status; #测试的时候看看在hit否?}
只对链接中的链接数做统计
在 http{} 中加入
limit_conn_zone $binary_remote_addr zone=limit:10m; #这边使用ip的二进制 如果是内部ip通过层层代理 可以使用 $proxy_add_x_forwarded_for 来计算limit_conn_log_level info;limit_conn_status 403;
在你加的server{} 中加入
location ~ /(zt|about|corpus|dm) {limit_conn limit 3;}
pigai_anquan.conf
## xss 安全if ( $args ~* "set([^&=]+)var" ) {return 403;}if ( $args ~* "set(.+)echo" ) {return 403;}if ( $args ~* "this\.src" ) {return 403;}if ( $args ~* "(iframe%3E|%2fiframe)" ) {return 403;}if ( $args ~* "(script%3E|%2fscript)" ) {return 403;}## 系统if ( $args ~* "(etc\/passwd)" ) {return 403;}#下面的范文比较大 请谨慎使用if ( $args ~* "%3C" ) {return 403;}if ( $args ~* "%3E" ) {return 403;}if ( $args ~* "\(*+\)" ) {return 403;}
使用OpenResty在 proxy_pass 下一行 或者 有php出现的地方加入
header_filter_by_lua_block {ngx.header["X-Powered-By"] = nil}
map $http_origin $corsHost {default 0;"~http://gj.pigai.org" http://gj.pigai.org;"~http://gj2.pigai.org:8081" http://gj2.pigai.org:8081;"~http://gj2.pigai.org" http://gj2.pigai.org;}//上面的放在 NGINX.conf 下 下面的放在 location 下if ($request_method = 'OPTIONS') {add_header 'Access-Control-Allow-Origin' $corsHost;add_header 'Access-Control-Allow-Credentials' 'true';add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';add_header 'Access-Control-Max-Age' 1728000;add_header 'Content-Type' 'text/plain charset=UTF-8';add_header 'Content-Length' 0;return 204;}if ($request_method = 'POST') {add_header 'Access-Control-Allow-Origin' $corsHost;add_header 'Access-Control-Allow-Credentials' 'true';add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';}if ($request_method = 'GET') {add_header 'Access-Control-Allow-Origin' $corsHost;add_header 'Access-Control-Allow-Credentials' 'true';add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';}