問題一:相同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/...