问题一:相同server_name多个虚拟主机优先级访问php
server{ listen 80; server_name server1; location{...} } server{ listen 80; server_name server2; location{...} }
解决方法:html
问题二:location匹配优先级nginx
location = /code1/ { rewrite ^(.*)$ /code1/index.html break; } location ~ /code.* { rewrite ^(.*)$ /code3/index.html break; } location ^~ /code { rewrite ^(.*)$ /code2/index.html break; }
知识填坑:git
解决方法:github
问题三:try_files使用正则表达式
location / { try_files $uri $uri/ /index.html; }
解决方法:shell
问题四:Nginx的alias和root区别数据库
location /request_path/img/ { root /local_path/img/; } location /request_path/img/ { alias /local_path/img/; }
解决方法:vim
问题五:经过多层代理,传递用户真实IP安全
解决方法:
set x_real_ip=$remote_addr $x_real_ip=真实IP
优化考虑点:
接口压力测试工具:ab
nginx关于系统的优化点:
vim /etc/nginx/nginx.conf user nginx; worker_processes 16; worker_cpu_affinity auto; worker_rlimit_nofile 15535; events{ use epoll; worker_connections 10240; } http{ include /etc/nginx/mime.types; default_type application/octet-stream; #Charset charset utf-8; log_format main ''; access_log /var/log/nginx/access.log main; #Core module sendfile on; keepalive_timeout 65; #Gzip module gzip on; gzip_disable "MSIE [1-6]\."; gzip_http_version 1.1; #Virtal server include /etc/nginx/conf.d/*.conf; }
问题:爬虫行为和恶意抓取、资源盗用
解决方法:
问题一:后台密码撞库,经过密码字典不断对后台系统登陆性尝试,获取后台密码
解决方法:
问题二:文件上传漏洞,利用能够上传的接口将恶意代码植入服务器中,再经过url访问以执行
解决方法:
针对一些木马和后缀等作必定的处理
location ^~ /upload{ root /usr/share/html; if($request_filename ~*(.*)\.php){ return 403; #拒绝访问 } }
问题三:SQL注入,利用未过滤或未审核的用户输入的攻击手段,让应用运行本不该该运行的SQL代码
解决方法:
使用nginx+Lua搭建安全waf防火墙
防火墙功能:
推荐已写好waf:https://github.com/loveshell/...