配置查询Nginx中异常IP处理

很多时候会发现好多,异常流量,处理这些异常流量,通常是封禁IP `# deny_ip_o.sh 文件内容 #!/bin/bash max=500 #我们设定的最大值,当访问量大于这个值得时候,封锁 logdir=/opt/nginx/logs/access.log #nginx 访问日志文件路径 confdir=/opt/nginx/logs/nginx_deny.log #检测文件 test -e <span class="katex math inline">{confdir} || touch</span>{confdir} port=443 drop_Ip="" #循环遍历日志文件取出访问量大于 500 的 ip for drop_Ip in <span class="katex math inline">(tail -n500000</span>logdir | awk '{print <span class="katex math inline">1}' | sort | uniq -c | sort -rn | awk '{if (</span>1>500) print <span class="katex math inline">2}') do echo "</span>{drop_Ip}---<span class="katex math inline">{drop_ip}" grep -q "</span>{drop_Ip}" <span class="katex math inline">{confdir} && eg=1 || eg=0; if ((</span>{eg}==0 ));then iptables -I INPUT -p tcp --dport <span class="katex math inline">{port} -s</span>{drop_Ip} -j DROP echo ">>>>> `date '+%Y-%m-%d %H%M%S'` - 发现攻击源地址 -> <span class="katex math inline">{drop_Ip} " >> /opt/nginx/logs/nginx_deny.log #记录 log fi done #################################################################### #!/bin/bash #_日志位置 _log_Path="/data0/nginx/weblogs/" #_日志文件名称 _log_FileName="access_blog.kinggoo.com.log" #_要被屏蔽的ip访问端口,默认80 _port="80" _nginx_deny="/opt/webserver/nginx/conf/deny.conf" _nginx_bin="/opt/webserver/nginx/sbin/nginx" _logfilepath=</span>{_log_Path}<span class="katex math inline">{_log_FileName} #初始化被禁ip变量 _drop_Ip="" #检测文件 test -e</span>{_nginx_deny} || touch <span class="katex math inline">{_nginx_deny} for _drop_Ip in</span>( tail -n50000 "<span class="katex math inline">{_logfilepath}" |awk '{print</span>1,<span class="katex math inline">12}' |grep -i -v -E "google|yahoo|baidu|msnbot|FeedSky|sogou|WordPress" |awk '{print</span>1}'|sort|uniq -c|sort -rn |awk '{if(<span class="katex math inline">1>1000)print ""</span>2""}' ); do grep -q "<span class="katex math inline">{_drop_Ip}"</span>{_nginx_deny} && eg=1 || eg=0 ; if (( <span class="katex math inline">{eg}==0 ));then echo "deny</span>{_drop_Ip};" >> <span class="katex math inline">{_nginx_deny}</span>{_nginx_bin} -s reload iptables -I INPUT -p tcp -dport <span class="katex math inline">{_port} -s</span>{_drop_Ip} -j DROP echo ">>>>> `date '+%Y-%m-%d %H%M%S'` - 发现攻击源地址 -> <span class="katex math inline">{_drop_Ip} " >> /tmp/nginx_deny.log; echo "iptables -I INPUT -p tcp --dport</span>{_port} -s <span class="katex math inline">{_drop_Ip} -j DROP" >> /tmp/nginx_deny.log fi done 使用 nginx 封锁 ... -封锁 IP #!/bin/bash max=500 #我们设定的最大值,当访问量大于这个值得时候,封锁 confdir=/usr/local/data/nginx/conf/blockip.conf #nginx 封锁配置文件路径 logdir=/usr/local/data/nginx/logs/access_huke88.log #nginx 访问日志文件路径 #检测文件 test -e</span>{confdir} || touch <span class="katex math inline">{confdir} drop_ip="" #循环遍历日志文件取出访问量大于 500 的 ip for drop_ip in</span>(cat <span class="katex math inline">logdir | awk '{print</span>1}' | sort | uniq -c | sort -rn | awk '{if (<span class="katex math inline">1>500) print</span>2}') do grep -q "<span class="katex math inline">{drop_Ip}"</span>{confdir} && eg=1 || eg=0; if (( <span class="katex math inline">{eg}==0 ));then echo "deny</span>{drop_Ip};">><span class="katex math inline">confdir #把“ deny IP ;”语句写入封锁配置文件中 echo ">>>>> `date '+%Y-%m-%d %H%M%S'` - 发现攻击源地址 -></span>{drop_Ip} " >> /usr/local/data/nginx/logs/nginx_deny.log #记录 log fi done service nginx reload -解锁 IP #!/bin/bash sed -i 's/^/#&/g' /usr/local/nginx/conf/blockip.conf #把 nginx 封锁配置文件中的内容注释掉 service nginx reload #重置 nginx 服务,这样就做到了解锁 IP 使用 iptables 封锁 ... -封锁 IP 脚本 #!/bin/bash max=500 #我们设定的最大值,当访问量大于这个值得时候,封锁 logdir=/usr/local/data/nginx/logs/access_huke88.log #nginx 访问日志文件路径 confdir=/usr/local/data/nginx/conf/blockip.conf #nginx 封锁配置文件路径 #检测文件 test -e <span class="katex math inline">{confdir} || touch</span>{confdir} port=80 drop_ip="" #循环遍历日志文件取出访问量大于 500 的 ip for drop_ip in <span class="katex math inline">(cat</span>logdir | awk '{print <span class="katex math inline">1}' | sort | uniq -c | sort -rn | awk '{if (</span>1>500) print <span class="katex math inline">2}') do grep -q "</span>{drop_Ip}" <span class="katex math inline">{confdir} && eg=1 || eg=0; if ((</span>{eg}==0 ));then iptables -I INPUT -p tcp --dport <span class="katex math inline">{port} -s</span>{drop_Ip} -j DROP echo ">>>>> `date '+%Y-%m-%d %H%M%S'` - 发现攻击源地址 -> <span class="katex math inline">{drop_Ip} " >> /usr/local/data/nginx/logs/nginx_deny.log #记录 log fi done ... 加入计划任务每五分钟执行一次 chmod +x /home/scripts/deny_ip.sh #####nginx 封 ip###### */5 * * * * /bin/sh /home/scripts/deny_ip.sh >/dev/null 2>&1 ### 添加定时任务 */5 * * * * /bin/sh /opt/nginx/logs/deny_ip_o.sh >/dev/null 2>&1 tail -n 500000 access.log | awk '{print</span>1,<span class="katex math inline">13,</span>8}'|awk '{print <span class="katex math inline">1}'|sort|uniq -c |sort -rn | awk '{if(</span>1>100)print "deny "<span class="katex math inline">1,</span>2";"}' tail -n 500000000 access.log | awk '{print <span class="katex math inline">1,</span>13,<span class="katex math inline">8}'|awk '{print</span>1}'|sort|uniq -c |sort -rn | awk '{if(<span class="katex math inline">1>100)print "deny "</span>2";"}' > blockip.conf tail -n 500000 access.log | awk '{print <span class="katex math inline">1,</span>13,<span class="katex math inline">8}'|awk '{print</span>1}'|sort|uniq -c |sort -rn | awk '{if(<span class="katex math inline">1>100)print "deny "</span>2";"}' >> blockip.conf #if (<span class="katex math inline">http_referer ~* "top1top1.top") { # rewrite ^/ http://top.top1top1.top/CallHelper/client/main.jsp; #} if (</span>http_referer ~* "top1top1.top") { return 404; } if (<span class="katex math inline">http_referer ~* "shandiandxshop.xyz"){ rewrite ^/ http://tt.shandiandxshop.xyz/CallHelper/client/index.jsp; } https://blog.csdn.net/qq_41018743/article/details/105491785 http://www.siwei.me/blog/posts/linux-nginx-ip-ip #################################################################### #!/bin/bash num=100 # 每秒某个ip的访问上限 list=`netstat -an |grep ^tcp.*:80|egrep -v 'LISTEN|127.0.0.1'|awk -F"[ ]+|[:]" '{print</span>6}'|sort|uniq -c|sort -rn|awk '{if (<span class="katex math inline">1></span>num){print <span class="katex math inline">2}}'` for i in</span>list do iptables -I INPUT -s <span class="katex math inline">i --dport 80 -j DROP echo ">>>>> `date '+%Y-%m-%d %H%M%S'` - 发现攻击源地址 -></span>{<span class="katex math inline">i} " >> /opt/nginx/logs/nginx_deny80.log #记录 log done ##################################################################### #!/bin/bash num=100 list=`netstat -an |grep ^tcp.*:80|egrep -v 'LISTEN|127.0.0.1'|awk -F"[ ]+|[:]" '{print</span>6}'|sort|uniq -c|sort -rn|awk '{if (<span class="katex math inline">1></span>num){print <span class="katex math inline">2}}'` for i in</span>list do iptables -I INPUT -p tcp --dport 80 -s <span class="katex math inline">{i} -j DROP echo ">>>>> `date '+%Y-%m-%d %H%M%S'` - 发现攻击源地址 -></span>{i} " >> /opt/nginx/logs/nginx_deny80.log done ####################################################################### #!/bin/bash max=500 #我们设定的最大值,当访问量大于这个值得时候,封锁 logdir=/opt/nginx/logs/access.log #nginx 访问日志文件路径 confdir=/opt/nginx/logs/nginx_deny.log #检测文件 test -e <span class="katex math inline">{confdir} || touch</span>{confdir} port=80 drop_ip="" #循环遍历日志文件取出访问量大于 500 的 ip for drop_ip in <span class="katex math inline">(tail -n5000000</span>logdir | awk '{print <span class="katex math inline">1}' | sort | uniq -c | sort -rn | awk '{if (</span>1>500) print <span class="katex math inline">2}') do grep -q "</span>{drop_Ip}" <span class="katex math inline">{confdir} && eg=1 || eg=0; if ((</span>{eg}==0 ));then iptables -I INPUT -p tcp --dport <span class="katex math inline">{port} -s</span>{drop_Ip} -j DROP echo ">>>>> `date '+%Y-%m-%d %H%M%S'` - 发现攻击源地址 -> <span class="katex math inline">{drop_Ip} " >> /opt/nginx/logs/nginx_deny.log #记录 log fi done #################################################################### #!/usr/bin/env bash echo "" echo " ========================================================= " echo " \ Nginx日志安全分析脚本 V1.0 / " echo " ========================================================= " echo " # 支持Nginx日志分析,攻击告警分析等 " echo " # author:al0ne " echo " # https://github.com/al0ne " echo -e "\n" #此脚本是参考nmgxy/klionsec修改而来,重新添加了一些特征,只用来临时救急,还是推荐到ELK或者Splunk中分析 #功能 ###统计Top 20 地址 ###SQL注入分析 ###SQL注入 FROM查询统计 ###扫描器/常用黑客工具 ###漏洞利用检测 ###敏感路径访问 ###文件包含攻击 ###HTTP Tunnel ###Webshell ###寻找响应长度的url Top 20 ###寻找罕见的脚本文件访问 ###寻找302跳转的脚本文件 #如果存在多个access文件或者有多个access.x.gz 建议先zcat access*.gz >> access.log文件中 #设置分析结果存储目录,结尾不能加/ outfile=/tmp/logs #如果目录以存在则清空,未存在则新建目录 if [ -d</span>outfile ]; then rm -rf <span class="katex math inline">outfile/* else mkdir -p</span>outfile fi #设置nginx日志目录,结尾必须加/ access_dir=/var/log/nginx/ #设置文件名,如果文件名为access那么匹配的是access*文件 access_log=access #判断日志文件是否存在 num=<span class="katex math inline">(ls</span>{access_dir}<span class="katex math inline">{access_log}* | wc -l) >/dev/null 2>&1 if [</span>num -eq 0 ]; then echo '日志文件不存在' exit 1 fi echo -e "\n" # 验证操作系统是debian系还是centos OS='None' if [ -e "/etc/os-release" ]; then source /etc/os-release case <span class="katex math inline">{ID} in "debian" | "ubuntu" | "devuan") OS='Debian' ;; "centos" | "rhel fedora" | "rhel") OS='Centos' ;; *) ;; esac fi if [</span>OS = 'None' ]; then if command -v apt-get >/dev/null 2>&1; then OS='Debian' elif command -v yum >/dev/null 2>&1; then OS='Centos' else echo -e "\n不支持这个系统\n" echo -e "已退出" exit 1 fi fi # 检测ag软件有没有安装 if ag -V >/dev/null 2>&1; then echo -e "\e[00;32msilversearcher-ag已安装 \e[00m" else if [ <span class="katex math inline">OS = 'Centos' ]; then yum -y install the_silver_searcher >/dev/null 2>&1 else apt-get -y install silversearcher-ag >/dev/null 2>&1 fi fi #如果检测别的日志请手动替换偏移,例如awk的</span>7代表url,<span class="katex math inline">9代表状态码,</span>10代表长度,本脚本是以nginx日志为基础 echo "分析结果日志:<span class="katex math inline">{outfile}" echo "Nginx日志目录:</span>{access_dir}" echo "Nginx文件名:<span class="katex math inline">{access_log}" echo -e "\n" echo -e "\e[00;31m[+]TOP 20 IP 地址\e[00m" ag -a -o --nofilename '\d+\.\d+\.\d+\.\d+'</span>{access_dir}<span class="katex math inline">{access_log}* | sort | uniq -c | sort -nr | head -n 20 | tee -a</span>{outfile}/top20.log echo -e "\n" echo -e "\e[00;31m[+]SQL注入攻击分析\e[00m" #在SQL注入中排除掉了一些扫描css/js/png图片类等无用告警,并且重点筛选状态码200或者500的告警 ag -a "xp_cmdshell|%20xor|%20and|%20AND|%20or|%20OR|select%20|%20and%201=1|%20and%201=2|%20from|%27exec|information_schema.tables|load_file|benchmark|substring|table_name|table_schema|%20where%20|%20union%20|%20UNION%20|concat\(|concat_ws\(|%20group%20|0x5f|0x7e|0x7c|0x27|%20limit|\bcurrent_user\b|%20LIMIT|version%28|version\(|database%28|database\(|user%28|user\(|%20extractvalue|%updatexml|rand\(0\)\*2|%20group%20by%20x|%20NULL%2C|sqlmap" <span class="katex math inline">{access_dir}</span>{access_log}* | ag -v '/\w+\.(?:js|css|html|jpg|jpeg|png|htm|swf)(?:\?| )' | awk '(<span class="katex math inline">9==200)||(</span>9==500) {print <span class="katex math inline">0}' ></span>{outfile}/sql.log awk '{print "SQL注入攻击" NR"次"}' <span class="katex math inline">{outfile}/sql.log | tail -n1 echo "SQL注入 TOP 20 IP地址" ag -o '(?<=:)\d+\.\d+\.\d+\.\d+'</span>{outfile}/sql.log | sort | uniq -c | sort -nr | head -n 20 | tee -a <span class="katex math inline">{outfile}/sql_top20.log # 重点关注from查询,是否存在脱裤行为,排除扫描行为 echo "SQL注入 FROM 查询" cat</span>{outfile}/sql.log | ag '\bfrom\b' | ag -v 'information_schema' ><span class="katex math inline">{outfile}/sql_from_query.log awk '{print "SQL注入FROM查询" NR"次"}'</span>{outfile}/sql_from_query.log | tail -n1 echo -e "\n" echo -e "\e[00;31m[+]扫描器scan & 黑客工具\e[00m" ag -a "acunetix|by_wvs|nikto|netsparker|HP404|nsfocus|WebCruiser|owasp|nmap|nessus|HEAD /|AppScan|burpsuite|w3af|ZAP|openVAS|.+avij|.+angolin|360webscan|webscan|XSS@HERE|XSS%40HERE|NOSEC.JSky|wwwscan|wscan|antSword|WebVulnScan|WebInspect|ltx71|masscan|python-requests|Python-urllib|WinHttpRequest" <span class="katex math inline">{access_dir}</span>{access_log}* | ag -v '/\w+\.(?:js|css|jpg|jpeg|png|swf)(?:\?| )' | awk '(<span class="katex math inline">9==200)||(</span>9==500) {print <span class="katex math inline">0}' ></span>{outfile}/scan.log awk '{print "共检测到扫描攻击" NR"次"}' <span class="katex math inline">{outfile}/scan.log | tail -n1 echo "扫描工具流量 TOP 20" ag -o '(?<=:)\d+\.\d+\.\d+\.\d+'</span>{outfile}/scan.log | sort | uniq -c | sort -nr | head -n 20 | tee -a <span class="katex math inline">{outfile}/scan_top20.log echo -e "\n" echo -e "\e[00;31m[+]敏感路径访问\e[00m" ag -a "/_cat/|/_config/|include=|phpinfo|info\.php|/web-console|JMXInvokerServlet|/manager/html|axis2-admin|axis2-web|phpMyAdmin|phpmyadmin|/admin-console|/jmx-console|/console/|\.tar.gz|\.tar|\.tar.xz|\.xz|\.zip|\.rar|\.mdb|\.inc|\.sql|/\.config\b|\.bak|/.svn/|/\.git/|\.hg|\.DS_Store|\.htaccess|nginx\.conf|\.bash_history|/CVS/|\.bak|wwwroot|备份|/Web.config|/web.config|/1.txt|/test.txt"</span>{access_dir}<span class="katex math inline">{access_log}* | awk '(</span>9==200)||(<span class="katex math inline">9==500) {print</span>0}' ><span class="katex math inline">{outfile}/dir.log awk '{print "共检测到针对敏感文件扫描" NR"次"}'</span>{outfile}/dir.log | tail -n1 echo "敏感文件访问流量 TOP 20" ag -o '(?<=:)\d+\.\d+\.\d+\.\d+' <span class="katex math inline">{outfile}/dir.log | sort | uniq -c | sort -nr | head -n 20 | tee -a</span>{outfile}/dir_top20.log echo -e "\n" echo -e "\e[00;31m[+]漏洞利用检测\e[00m" ag -a "%00|/win.ini|/my.ini|\.\./\.\./|/etc/shadow|%0D%0A|file:/|gopher:/|dict:/|WindowsPowerShell|/wls-wsat/|call_user_func_array|uddiexplorer|@DEFAULT_MEMBER_ACCESS|@java\.lang\.Runtime|OgnlContext|/bin/bash|cmd\.exe|wget\s|curl\s|s=/index/\think" <span class="katex math inline">{access_dir}</span>{access_log}* | awk '(<span class="katex math inline">9==200)||(</span>9==500) {print <span class="katex math inline">0}' ></span>{outfile}/exploit.log awk '{print "漏洞利用探测" NR"次"}' <span class="katex math inline">{outfile}/exploit.log | tail -n1 echo "漏洞利用检测 TOP 20" ag -o '(?<=:)\d+\.\d+\.\d+\.\d+'</span>{outfile}/exploit.log | sort | uniq -c | sort -nr | head -n 20 | tee -a <span class="katex math inline">{outfile}/exploit_top20.log echo -e "\n" echo -e "\e[00;31m[+]webshell\e[00m" ag -a "=whoami|dbname=|exec=|cmd=|\br57\b|\bc99\b|\bc100\b|\bb374k\b|adminer.php|eval\(|assert\(|%eval|%execute|tunnel\.[asp|php|jsp|aspx]{3,4}|makewebtaski|ma\.[asp|php|jsp|aspx]{3,4}|\bup\.[asp|php|jsp|aspx]{3,4}|cmd\.[asp|php|jsp|aspx]{3,4}|201\d\.[asp|php|jsp|aspx]{3,4}|xiaoma\.[asp|php|jsp|aspx]{3,4}|shell\.[asp|php|jsp|aspx]{3,4}|404\.[asp|php|jsp|aspx]{3,4}|tom\.[asp|php|jsp|aspx]{3,4}|k8cmd\.[asp|php|jsp|aspx]{3,4}|ver[0-9]{3,4}\.[asp|php|jsp|aspx]{3,4}|\.aar|[asp|php|jsp|aspx]{3,4}spy\.|o=vLogin|aioshell|admine|ghost\.[asp|php|jsp|aspx]{3,4}|r00ts|90sec|t00ls|editor\.aspx|wso\.[asp|aspx]{3,4}"</span>{access_dir}<span class="katex math inline">{access_log}* | awk '(</span>9==200)||(<span class="katex math inline">9==500) {print</span>0}' ><span class="katex math inline">{outfile}/webshell.log awk '{print "共检测到webshell行为" NR "次"}'</span>{outfile}/webshell.log | tail -n1 echo "Webshell TOP 20" ag -o '(?<=:)\d+\.\d+\.\d+\.\d+' <span class="katex math inline">{outfile}/webshell.log | sort | uniq -c | sort -nr | head -n 20 | tee -a</span>{outfile}/webshell_top20.log echo -e "\n" echo -e "\e[00;31m[+]HTTP Tunnel\e[00m" #Regeorg代理特征 ag -a "cmd=disconnect|cmd=read|cmd=forward|cmd=connect|127.0.0.1" <span class="katex math inline">{access_dir}</span>{access_log}* | awk '(<span class="katex math inline">9==200)||(</span>9==500) {print <span class="katex math inline">0}' | tee -a</span>{outfile}/tunnel.log awk '{print "共检测到隧道行为" NR "次"}' <span class="katex math inline">{outfile}/tunnel.log | tail -n1 echo -e "\n" echo -e "\e[00;31m[+]Top 20 url响应长度\e[00m" # 查找url响应长度最长的url排序,目的是有没有下载服务器的一些打包文件 len=</span>(cat <span class="katex math inline">{access_dir}</span>{access_log}* | awk '{print <span class="katex math inline">10}' | sort -nr | head -n 20) echo</span>len | awk 'BEGIN{ RS=" " }{ print <span class="katex math inline">0 }' | xargs -i{} ag -a --nocolor '\d+\s{}\s'</span>{access_dir}<span class="katex math inline">{access_log}* | awk '{print</span>7,<span class="katex math inline">10}' | sort | uniq | sort -k 2 -nr | tee -a</span>{outfile}/url_rsp_len.log echo -e "\n" echo -e "\e[00;31m[+]罕见的脚本文件访问\e[00m" echo "访问量特别特别少的脚本文件极有可能是webshell" cat <span class="katex math inline">{access_dir}</span>{access_log}* | awk '(<span class="katex math inline">9==200)||(</span>9==500) {print <span class="katex math inline">7}' | sort | uniq -c | sort -n | ag -v '\?' | ag '\.php|\.jsp|\.asp|\.aspx' | head -n 20 | tee -a</span>{outfile}/rare_url.log echo -e "\n" echo -e "\e[00;31m[+]302跳转\e[00m" echo "此目的是寻找一些登录成功的脚本文件" cat <span class="katex math inline">{access_dir}</span>{access_log}* | awk '(<span class="katex math inline">9==302)||(</span>9==301) {print <span class="katex math inline">7}' | sort | uniq -c | sort -n | ag -v '\?' | ag '\.php|\.jsp|\.asp|\.aspx' | head -n 20 | tee -a</span>{outfile}/302_goto.log echo -e "\n" ###################################################################### #!/bin/bash echo "##########################################################################" echo "# nginx日志分析小工具,author:william,https://github.com/xiucaiwu #" echo "# 本工具暂时不支持跨天日志分析,Nginx日志格式为默认格式 #" echo "# 请输入要分析的时段(为空则分析全部日志): #" echo "# 分析今天3点10分到5点的数据:03:10-05:00 "-"前后没有空格 #" echo "# 分析2018年8月20号3点到5点的数据:2018-08-20 03:00-05:00 #" echo "##########################################################################" # 默认存放切割后的Nginx日志目录 default_parse_ngx_dir_path='/opt/log/nginx' # 生成的切割后的Nginx日志路径 parse_ngx_path="" # 默认Nginx日志路径 #default_ngx_path="/usr/local/nginx/logs/host.access.145.`date "+%Y%m%d"`.log" default_ngx_path="/root/wwwlog/access.log" # 记录用户手动输入Nginx日志路径的字符串长度 ngx_path_len=0 # 记录用户手动输入切割后的Nginx日志目录字符串长度 ngx_dir_path_len=0 # 一个空数组 array=() # 一个字符串分割另一个字符串 function str_split(){ # 分割字符串 delimiter=<span class="katex math inline">1 # 目标字符串 string=</span>2 # 注意后面有个空格 array=(<span class="katex math inline">{string//</span>delimiter/ }) # return 只能返回int型数值 # return <span class="katex math inline">arr } read -p "请输入nginx日志文件路径:" ngx_path ngx_path_len=`echo</span>ngx_path | wc -L` if [ `echo <span class="katex math inline">ngx_path | wc -L` == 0 ];then ngx_path=</span>default_ngx_path fi if [ ! -f <span class="katex math inline">ngx_path ];then echo "日志不存在" # exit fi read -p "请输入存放分析后的nginx日志文件夹路径,默认为/opt/log/nginx:" ngx_parse_dir_path if [ `echo</span>ngx_dir_path | wc -L` == 0 ];then ngx_parse_dir_path=<span class="katex math inline">default_parse_ngx_dir_path fi if [ ! -d</span>ngx_parse_dir_path ];then echo <span class="katex math inline">ngx_parse_dir_path "不存在" # exit fi read -p "请输入要分析的时段(24小时制):" ngx_time # 统计输入的字符串长度 len=`echo</span>ngx_time | wc -L` if [ <span class="katex math inline">len == 0 ];then # 当前是几时几分 hour_minute=`date +%H:%I` filename=`date +%Y%m%d`".log" mydate=`date +%d/%b/%Y` parse_ngx_path=</span>ngx_parse_dir_path/<span class="katex math inline">filename echo -e "\033[32m 文件</span>{parse_ngx_path}正在生成... \033[0m" awk -v mydate=<span class="katex math inline">mydate -v arr=</span>hour_minute -F "[ /:]" '<span class="katex math inline">1"/"</span>2"/"<span class="katex math inline">3==mydate &&</span>4":"<span class="katex math inline">5>="00:00" &&</span>4":"<span class="katex math inline">5<=arr'</span>ngx_path > <span class="katex math inline">parse_ngx_path echo -e "\033[32m 文件</span>{parse_ngx_path}生成成功!!! \033[0m" elif [ <span class="katex math inline">len == 11 ];then # 统计"-"出现的次数 if [ `echo</span>ngx_time | grep -o '-' | wc -l` == 1 ];then # 当前日期 current_date=`date "+%Y-%m-%d %H:%M"` # 当前日期对应的时间戳 current_timestamp=`date -d "<span class="katex math inline">current_date" +%s` str_split "-"</span>ngx_time # 用户输入的日期 user_date="`date \"+%Y-%m-%d\"` <span class="katex math inline">{array[0]}" # 用户输入的日期对应的时间戳 user_timestamp=`date -d "</span>user_date" +%s` filename=`date +%Y%m%d`"[<span class="katex math inline">{array[0]}-</span>{array[1]}].log" mydate=`date +%d/%b/%Y` parse_ngx_path=<span class="katex math inline">ngx_parse_dir_path/</span>filename if [ <span class="katex math inline">user_timestamp ==</span>current_timestamp ];then echo -e "\033[32m 文件<span class="katex math inline">{parse_ngx_path}正在生成... \033[0m" awk -v mydate=</span>mydate -v arr1=<span class="katex math inline">{array[0]} -v arr2=</span>{array[1]} -F "[ /:]" '<span class="katex math inline">1"/"</span>2"/"<span class="katex math inline">3==mydate &&</span>4":"<span class="katex math inline">5>=arr1 &&</span>4":"<span class="katex math inline">5<=arr2'</span>ngx_path > <span class="katex math inline">parse_ngx_path echo -e "\033[32m 文件</span>{parse_ngx_path}生成成功!!! \033[0m" elif [ ! -f <span class="katex math inline">parse_ngx_path ];then echo -e "\033[32m 文件</span>{parse_ngx_path}正在生成... \033[0m" awk -v mydate=<span class="katex math inline">mydate -v arr1=</span>{array[0]} -v arr2=<span class="katex math inline">{array[1]} -F "[ /:]" '</span>1"/"<span class="katex math inline">2"/"</span>3==mydate && <span class="katex math inline">4":"</span>5>=arr1 && <span class="katex math inline">4":"</span>5<=arr2' <span class="katex math inline">ngx_path ></span>parse_ngx_path echo -e "\033[32m 文件<span class="katex math inline">{parse_ngx_path}生成成功!!! \033[0m" fi else echo "格式输入不正确" exit fi elif [</span>len == 22 ];then # 统计"-"出现的次数 if [ `echo <span class="katex math inline">ngx_time | grep -o '-' | wc -l` == 3 ];then str_split " " "</span>ngx_time" # 自定义日期格式 mydate1=`date -d "<span class="katex math inline">{array[0]}" +%d/%b/%Y` # 日期转时间戳 timestamp=`date -d "</span>{array[0]}" +%s` # 时间戳转日期 mydate2=`date -d @<span class="katex math inline">timestamp "+%Y%m%d"` str_split "-"</span>{array[1]} filename=<span class="katex math inline">mydate2"[</span>{array[0]}-<span class="katex math inline">{array[1]}].log" parse_ngx_path=</span>ngx_parse_dir_path/<span class="katex math inline">filename if [ ! -f</span>parse_ngx_path ];then echo -e "\033[32m 文件<span class="katex math inline">{parse_ngx_path}正在生成... \033[0m" awk -v mydate=</span>mydate1 -v arr1=<span class="katex math inline">{array[0]} -v arr2=</span>{array[1]} -F "[ /:]" '<span class="katex math inline">1"/"</span>2"/"<span class="katex math inline">3==mydate &&</span>4":"<span class="katex math inline">5>=arr1 &&</span>4":"<span class="katex math inline">5<=arr2'</span>ngx_path > <span class="katex math inline">parse_ngx_path echo -e "\033[32m 文件</span>{parse_ngx_path}生成成功!!! \033[0m" fi else echo "格式输入不正确" exit fi else echo "格式输入不正确" exit fi # 开始解析切割后的Nginx日志 if [ ! -f <span class="katex math inline">parse_ngx_path ];then echo -e "\033[31m 文件</span>{parse_ngx_path}不存在 \033[0m" fi # 统计访问最多的ip echo -e "\033[31m 访问TOP10的IP: \033[0m" awk '{print <span class="katex math inline">1}'</span>parse_ngx_path | sort | uniq -c | sort -n -k 1 -r | head -n 10 ip_array=`(awk '{print <span class="katex math inline">1}'</span>parse_ngx_path | sort | uniq -c | sort -n -k 1 -r | head -n 10 | awk '{print <span class="katex math inline">2}')` # 统计访问最多的url echo -e "\033[31m 访问TOP10的URL: \033[0m" awk '{print</span>7}' <span class="katex math inline">parse_ngx_path | sort |uniq -c | sort -rn | head -n 10 # 统计ip对应的url for i in</span>{ip_array[@]};do echo -e "\033[31m IP(<span class="katex math inline">{i})访问TOP10的URL: \033[0m" cat access.log | grep</span>i |awk '{print $7}'| sort | uniq -c | sort -rn | head -10 | more done`

2020年11月27日 · 11 分钟 · 天边的星星

如何伪装Nginx的banner内容

我们常用的curl这个命令,curl可以查看服务器web server的banner信息: 如: C:Documents and SettingsAdministrator>curl -I www.dangdang.com HTTP/1.1 200 OK Server: nginx/0.7.61(当当到目前为止用的还是nginx/0.7.61) C:Documents and SettingsAdministrator>curl -I www.360buy.com HTTP/1.0 200 OK Server: jdws (几个月前我就看还是nginx,做手脚啦!) 来个猛一点的 C:Documents and SettingsAdministrator>curl -I www.google.com HTTP/1.1 302 Found Server: gws (google自己开发的ws) 我们可以看清每家公司的web—server,当然也为黑客入侵提供了信息。如果你的这版ws存在一个致命bug,那可就惨啦。哪有没有一种办法可以修改ws信息哪?答案自然是有。下面介绍一种修改nginx的banner信息的方法。 方法很简单: 安装nginx时,在./configure后不要马上安装。而是进到安装文件的../src/core/目录下找到nginx.h用vi编辑器进行修改,如下: #define NGINX_VERSION “1.1.1” #define NGINX_VER “nginx/” NGINX_VERSION #define NGINX_VAR “NGINX” 改为(自定义) #define NGINX_VERSION “0.0.1” #define NGINX_VER “zhuzhu/” NGINX_VERSION #define NGINX_VAR “zhuzhu” 然后再执行make && make install 这回来看看我们自己的nginx ws显示成啥样 C:Documents and SettingsAdministrator>curl -I 192.168.0.111 HTTP/1.1 200 OK Server: zhuzhu/0.0.1 ...

2020年6月5日 · 1 分钟 · 天边的星星

阿里云OSS之Nginx反向代理配置

nginx配置 设置代理 upstream ossproxy{ server zcpcimgs.oss-cn-beijing.aliyuncs.com; } 配置代理 server { listen 80; server_name zc2019.com; location /data { proxy_pass http://ossproxy; proxy_redirect off; proxy_set_header Host zcpcimgs.oss-cn-beijing.aliyuncs.com; proxy_set_header X-Real-IP remote_addr; proxy_set_header X-Forwarded-Forproxy_add_x_forwarded_for; proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504; proxy_max_temp_file_size 0; proxy_connect_timeout 90; proxy_send_timeout 90; proxy_read_timeout 90; proxy_buffer_size 4k; proxy_buffers 4 32k; proxy_busy_buffers_size 64k; proxy_temp_file_write_size 64k; } location / { # root html; # index index.html index.htm; proxy_pass http://zcjfweb; # 真实信息 proxy_set_header Host host; proxy_set_header X-Real-IPremote_addr; proxy_set_header X-Forwarded-For proxy_add_x_forwarded_for; client_max_body_size 100M; proxy_read_timeout 30000; proxy_send_timeout 75s; #proxy_redirect off; #proxy_pass_header Set-Cookie; #proxy_hide_header X-Powered-By; #proxy_hide_header X-Mod-Pagespeed; #proxy_ignore_client_abort off; #proxy_cache_valid any 10m; #proxy_connect_timeout 75s; #proxy_read_timeout 75s; #proxy_send_timeout 75s; } ...

2019年3月19日 · 2 分钟 · 天边的星星

Nginx 301重定向域名

## 为何要使用301重定向 在网站建设中需要网页重定向的情况很多:如网页目录结构变动,网页重命名、网页的扩展名改变、网站域名改变等。如果不做重定向,用户的收藏和搜索引擎数据库中的旧地址只能让访客得到一个404错误信息页面,访问流量白白丧失。不仅如此,之前该页面的一切积累(比如PR值)就都白费了。 301重定向不仅能使页面实现自动跳转,对于搜索引擎来说,也可能可以传递PR值。   **nginx重定向规则详细介绍**   [http://www.jefflei.com/post/1015.html](http://www.jefflei.com/post/1015.html) **rewrite命令** nginx的rewrite相当于apache的rewriterule(大多数情况下可以把原有apache的rewrite规则加上引号就可以直接使用),它可以用在server,location 和IF条件判断块中,命令格式如下: rewrite 正则表达式 替换目标 flag标记 flag标记可以用以下几种格式: last – 基本上都用这个Flag。 break – 中止Rewirte,不在继续匹配 redirect – 返回临时重定向的HTTP状态302 permanent – 返回永久重定向的HTTP状态301 例如下面这段设定nginx将某个目录下面的文件重定向到另一个目录,2对应第二个括号(.)中对应的字符串: location /download/ { rewrite ^(/download/.)/m/(.).. 1/nginx-rewrite/2.gz break; } **nginx重定向的IF条件判断** 在server和location两种情况下可以使用nginx的IF条件判断,条件可以为以下几种: 正则表达式 如: 匹配判断 ~ 为区分大小写匹配; !~为区分大小写不匹配 ~* 为不区分大小写匹配;!~为不区分大小写不匹配 例如下面设定nginx在用户使用ie的使用重定向到/nginx-ie目录下: if (http_user_agent ~ MSIE) { rewrite ^(.*) /nginx-ie/$1 break; } **文件和目录判断 ** -f和!-f判断是否存在文件 -d和!-d判断是否存在目录 -e和!-e判断是否存在文件或目录 -x和!-x判断文件是否可执行 例如下面设定nginx在文件和目录不存在的时候重定向: if (!-e $request_filename) { proxy_pass http://127.0.0.1/; } ...

2018年12月10日 · 5 分钟 · 天边的星星

Nginx虚拟目录alias和root目录

nginx是通过alias设置虚拟目录,在nginx的配置中,alias目录和root目录是有区别的: 1)alias指定的目录是准确的,即location匹配访问的path目录下的文件直接是在alias目录下查找的; 2)root指定的目录是location匹配访问的path目录的上一级目录,这个path目录一定要是真实存在root指定目录下的; 3)使用alias标签的目录块中不能使用rewrite的break(具体原因不明);另外,alias指定的目录后面必须要加上”/”符号!! 4)alias虚拟目录配置中,location匹配的path目录如果后面不带”/”,那么访问的url地址中这个path目录后面加不加”/”不影响访问,访问时它会自动加上”/”; 但是如果location匹配的path目录后面加上”/”,那么访问的url地址中这个path目录必须要加上”/”,访问时它不会自动加上”/”。如果不加上”/”,访问就会失败! 5)root目录配置中,location匹配的path目录后面带不带”/”,都不会影响访问。 举例说明(比如nginx配置的域名是www.wangshibo.com): (1) location /huan/ { alias /home/www/huan/; } 在上面alias虚拟目录配置下,访问http://www.wangshibo.com/huan/a.html实际指定的是/home/www/huan/a.html。 注意:alias指定的目录后面必须要加上”/”,即/home/www/huan/不能改成/home/www/huan 上面的配置也可以改成root目录配置,如下,这样nginx就会去/home/www/huan下寻找http://www.wangshibo.com/huan的访问资源,两者配置后的访问效果是一样的! location /huan/ { root /home/www/; } (2) 上面的例子中alias设置的目录名和location匹配访问的path目录名一致,这样可以直接改成root目录配置;那要是不一致呢? 再看一例: location /web/ { alias /home/www/html/; } 访问http://www.wangshibo.com/web的时候就会去/home/www/html/下寻找访问资源。 这样的话,还不能直接改成root目录配置。 如果非要改成root目录配置,就只能在/home/www下将html->web(做软连接,即快捷方式),如下: location /web/ { root /home/www/; } # ln -s /home/www/web /home/www/html //即保持/home/www/web和/home/www/html内容一直 所以,一般情况下,在nginx配置中的良好习惯是: 1)在location /中配置root目录; 2)在location /path中配置alias虚拟目录。 如下一例: server { listen 80; server_name www.wangshibo.com; index index.html index.php index.htm; access_log /usr/local/nginx/logs/image.log; location / { root /var/www/html; } ...

2018年3月27日 · 1 分钟 · 天边的星星

Nginx应用之Location路由反向代理及重写策略

一、常用设置 1、日志格式 log_format main '<span class="katex math inline">time_iso8601|</span>remote_addr|<span class="katex math inline">remote_user|</span>request_method|<span class="katex math inline">uri|' '</span>status|<span class="katex math inline">request_time|</span>request_length|<span class="katex math inline">body_bytes_sent|</span>bytes_sent|' '<span class="katex math inline">connection|</span>http_x_forwarded_for|<span class="katex math inline">upstream_addr|</span>upstream_status|' '<span class="katex math inline">upstream_response_time|</span>args|<span class="katex math inline">http_referer|</span>http_user_agent'; access_log logs/access.log main; 2、反向代理透传客户端IP设置 proxy_set_header Host <span class="katex math inline">http_host; proxy_set_header X-Real-IP</span>remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 3、全局变量 $args #这个变量等于请求行中的参数。 $content_length #请求头中的Content-length字段。 $content_type #请求头中的Content-Type字段。 $document_root #当前请求在root指令中指定的值。 $host #请求主机头字段,否则为服务器名称。 $http_user_agent #客户端agent信息 $http_cookie #客户端cookie信息 $limit_rate #这个变量可以限制连接速率。 $request_body_file #客户端请求主体信息的临时文件名。 $request_method #客户端请求的动作,通常为GET或POST。 $remote_addr #客户端的IP地址。 $remote_port #客户端的端口。 $remote_user #已经经过Auth Basic Module验证的用户名。 $request_filename #当前请求的文件路径,由root或alias指令与URI请求生成。 $query_string #与$args相同。 $scheme #HTTP方法(如http,https)。 $server_protocol #请求使用的协议,通常是HTTP/1.0或HTTP/1.1。 $server_addr #服务器地址,在完成一次系统调用后可以确定这个值。 $server_name #服务器名称。 $server_port #请求到达服务器的端口号。 $request_uri #包含请求参数的原始URI,不包含主机名,如:”/foo/bar.php?arg=baz”。 $uri #不带请求参数的当前URI,$uri不包含主机名,如”/foo/bar.html”。 $document_uri #与$uri相同。 二、Rewrite规则 ...

2018年2月17日 · 2 分钟 · 天边的星星

Nginx 配置文件服务器下载apk和ipa

在nginx配置文件 mime.types中配置 application/vnd.android.package-archive apk; application/iphone pxl ipa; 这样apk在界面中就可以下载并提示安装 服务器iis支持.apk文件下载的设置 IIS服务器不能下载.apk文件的原因:iis的默认MIME类型中没有.apk文件,所以无法下载。 IIS服务器不能下载.apk文件的解决办法:既然.apk无法下载是因为没有MIME,那么添加一个MIME类型就可以了。 IIS服务器不能下载.apk文件的解决步骤: 打开IIS服务管理器,找到服务器,右键-属性,打开IIS服务属性; 单击MIME类型下的“MIME类型”按钮,打开MIME类型设置窗口; 单击“新建”,建立新的MIME类型; 扩展名中填写“.apk”, MIME类型中填写apk的MIME类型“ application/vnd.android.package-archive ” 单击“确定”保存设置。 重启IIS,使设置生效。 服务器apache支持.apk文件下载的设置 在Apache安装目录下的conf/mime.types文件的对应位置,加上以下一行语句,指定APK文件的MIME类型为 application/vnd.android.package-archive 即可: application/vnd.android.package-archive apk; 重启apache即可 服务器nginx支持.apk文件下载的设置 apk 和 .ipa分别是android应用和ios应用的扩展名。 如果在浏览器下载这些文件为后缀的文件时,会自动重命名为zip文件。 当然可以下载后手动修改后缀,依然可以安装。 如果想下载后缀直接就是apk ipa的,可以修改 /usr/local/nginx/conf目录下的mime.types 增加如下配置,重启nginx生效 application/vnd.android.package-archive apk; application/iphone pxl ipa; 少人做了Android的APP应用且放在了外网上,但是手机用户通过url找到了apk文件却无法实现下载,也或者下载后无法自动安装。针对这样一些问题今天进行了一个技术性的汇总,希望可以帮到那些为此问题烦恼的Android开发者。 写了一些 android 的应用放在网站上让人下载,在某些机型上,三星的 android 的 4.0 以上多款机型最普遍, 用安卓自带浏览器下载程序,会提示 “无法打开文件”,导致下载后不能直安装. 一般性只能采用下面方法解决: 1、用 UC 来下载安装,但这样就要求客户要用 UC 才可下载及安装我们的系统 2、叫用户自己在 android 在桌面上,打开文件夹, 则该 apk 点击时即可安装 问题:某些 android 自带浏览器 , 可能 对下载的 apk 安装进行了限制。 我想通过自己办法,例如修改 apk 或者加某些编译参数,能否解决这种安装的兼容问题 ? 最终人性化的解决方法: (1)、在IIS服务器上,MIME类型中添加一个: 文件扩展名: .apk MIME类型: application/vnd.android.package-archive (2)、服务端部署在tomcat下,已经在tomcat的web.xml里面配置了mini type ...

2017年11月17日 · 1 分钟 · 天边的星星

Nginx单IP地址配置多个SSL证书

默认情况下,Nginx一个IP地址仅支持一个SSL证书,需要多个IP地址才能配置多个SSL证书,在公网IP地址有限的情况下,可以使用TLS Server Name Indication extension(SNI, RFC 6066),它允许浏览器在SSL握手的时候发送请求的server name,也就是 Host,这样 Nginx 就能找到对应server 的SSL配置。 配置步骤如下: 1、检查Nginx是否支持TLS nginx -V … TLS SNI support enabled … nginx -V … TLS SNI support enabled … 2、如果出现TLS SNI support disable,就得升级openssl版本,并且重新编译nginx。 具体步骤如下: 首先下载openssl(建议下载1.0.1h版本) #wget http://www.openssl.org/source/openssl-1.0.1h.tar.gz 下载Nginx #wget http://nginx.org/download/nginx-1.9.9.tar.gz 解压openssl #tar -zxvf openssl-1.0.1h.tar.gz 解压nginx,并编译 #tar -zxvf nginx-1.9.9.tar.gz #cd nginx-1.9.9 #make && make install #检查Nginx版本信息 #/usr/local/nginx/sbin/nginx -V nginx version: nginx/1.9.9 built by gcc 4.1.2 20080704 (Red Hat 4.1.2-55) built with OpenSSL 1.0.1h 5 Jun 2014 TLS SNI support enabled ...

2017年1月11日 · 1 分钟 · 天边的星星

CentOS+Nginx一步一步开始配置负载均衡

Nginx负载均衡的理解 Nginx是一个轻量级的、高性能的WebServer,他主要可以干下面两件事: 作为http服务器(和apache的效果一样) 作为反向代理服务器实现负载均衡 现在Nginx到处都可以见到,经常会看到宕机后的网页会显示nginx的字样,这也说明Nginx由于高性能、使用配置简、开源单这些特点被越来越多的用户所接受,所使用。 其中第一种作为http服务器,结合php-fpm进程,对发来的请求进行处理,nginx本身并不会解析php,他只是作为一个服务器,接受客户端发来的请求,如果是php请求,则交给php进程处理,并将php处理完成之后的结果发送给客户端。这个很简单,安装好nginx+php-fpm之后配置好各自的配置文件,启动就可以实现。运行原理可以看下面这段解释: Nginx不支持对外部程序的直接调用或者解析,所有的外部程序(包括PHP)必须通过FastCGI接口来调用。FastCGI接口在Linux下是socket(这个socket可以是文件socket,也可以是ip socket)。为了调用CGI程序,还需要一个FastCGI的wrapper(wrapper可以理解为用于启动另一个程序的程序),这个wrapper绑定在某个固定socket上,如端口或者文件socket。当Nginx将CGI请求发送给这个socket的时候,通过FastCGI接口,wrapper接收到请求,然后派生出一个新的线程,这个线程调用解释器或者外部程序处理脚本并读取返回数据;接着,wrapper再将返回的数据通过FastCGI接口,沿着固定的socket传递给Nginx;最后,Nginx将返回的数据发送给客户端。这就是Nginx+FastCGI的整个运作过程,如图下图所示。 [][1] 上面这段话解释了nginx+fastcgi的运行机制,在nginx配置文件中会对请求进行匹配,并作做出相应的处理,比如说直接返回错误文件(这里和上面说的有点区别,我估计是nginx内部对html等这些静态文件可以做类似上图的解析),使用php进程对php请求进行处理(这里的php进程可以是多个)。 第二种是用反向代理事项负载均衡,这个其实其实很简单,说起来就是自己定义一组server,对请求进行匹配,并将请求转给server中的任意一个处理,来减轻每个server的压力,先看看网上对反向向代理的定义: 反向代理(Reverse Proxy)方式是指以代理服务器来接受internet上的连接请求,然后将请求转发给内部网络上的服务器,并将从服务器上得到的结果返回给internet上请求连接的客户端,此时代理服务器对外就表现为一个反向代理服务器。 反向代理是和正向代理(或者叫代理) 相反的,代理大家定听过吧,为了更方便的访问B资源,通过A资源间接的访问B资源,特点就是用户知道自己最终要访问的网站是什么,但是反向代理用户是不知道代理服务器后边做了什么处理的,反向代理中服务真正的处理服务器放在内网,对外网而言只可以访问反向代理服务器,这也大大提高了安全性。 安装软件 nginx安装很简单 1、安装nginx需要的环境,pcre(作用rewrite)、zlib(作用压缩)、ssl,这个也可以自己下载编译安装 yum -y install zlib; yum –y install pcre; yum –y install openssl; 2、下载安装nginx-*.tar.gz。 tar –zxvf nginx-1.2.8.tar.gz –C ./; cd nginx-1.2.8; ./congigure –prefix=/usr/local/nginx; make && make install; 3、配置 这里配置的时候只需要修改http{}之间的内容就行了,修改的第一个地方就是设置服务器组,在http节点之间添加 upstream myServer{ server www.88181.com:80; #这里是你自己要做负载均衡的服务器地址1 server www.linux.com:8080; #这里是要参与负载均衡的地址2 } nginx中的upstream支持下面几种方式:轮询(默认,按照时间顺序对所有服务器一个一个的访问,如果有服务器宕机,会自动剔除)、weight(服务器的方位几率和weight成正比,这个可以在服务器配置不均的时候进行配置)、ip_hash(对每个请求的ip进行hash计算,并按照一定的规则分配对应的服务器)、fair(按照每台服务器的响应时间(rt)来分配请求,rt晓得优先分配)、url_hash(按照访问url的hash值来分配请求),我这里使用了默认的轮训方式。 将请求指向myServer location / { proxy_pass http://myServer; } 完整的文件(删除注释)如下: worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; upstream myServer{ server www.linux.com:80; server www.88181.com:8080; } server { listen 80; server_name my22; location / { proxy_pass http://myServer; } } } 设置反向代理后端作为负载均衡的两个服务器 ...

2016年8月18日 · 1 分钟 · 天边的星星

Nginx 0.8.x + PHP 5.2.13(FastCGI)搭建胜过Apache十倍的Web服务器(第6版)

中文的维基百科:http://wiki.nginx.org/NginxChs 以下内容转自http://zyan.cc/nginx_php_v6/ 前言:本文是我撰写的关于搭建“Nginx + PHP(FastCGI)”Web服务器的第6篇文章。本系列文章作为国内最早详细介绍 Nginx + PHP 安装、配置、使用的资料之一,为推动 Nginx 在国内的发展产生了积极的作用。本文可能不断更新小版本,请记住原文链接“http://blog.zyan.cc/nginx_php_v6/”,获取最新内容。第6篇文章主要介绍了Nginx 0.8.x新的平滑重启方式,将PHP升级到了5.2.14,修正了PEAR问题。另将MySQL 5.1.x升级到了5.5.x系列,配置文件变更较大。 链接:《2007年9月的第1版》、《2007年12月的第2版》、《2008年6月的第3版》、《2008年8月的第4版》、《2009年5月的第5版》 Nginx (“engine x”) 是一个高性能的 HTTP 和反向代理服务器,也是一个 IMAP/POP3/SMTP 代理服务器。 Nginx 是由 Igor Sysoev 为俄罗斯访问量第二的 Rambler.ru 站点开发的,它已经在该站点运行超过三年了。Igor 将源代码以类BSD许可证的形式发布。 Nginx 超越 Apache 的高性能和稳定性,使得国内使用 Nginx 作为 Web 服务器的网站也越来越多,其中包括新浪博客、新浪播客、网易新闻、腾讯网、搜狐博客等门户网站频道,六间房、56.com等视频分享网站,Discuz!官方论坛、水木社区等知名论坛,盛大在线<sp ...

2014年8月4日 · 1 分钟 · 天边的星星