国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網站 > Nginx > 正文

nginx常見問題整理和解決辦法

2024-08-30 12:25:16
字體:
來源:轉載
供稿:網友

以下就是我們整理的nginx常見的問題,解決辦法我們例舉了1-2種,大家可以都測試下。

常見問題

問題一:相同server_name多個虛擬主機優先級訪問

server{ listen 80; server_name server1; location{...}}server{ listen 80; server_name server2; location{...}}

解決方法:

配置兩個conf文件:server1.conf 和 server2.conf

根據Linux系統中文件順序讀取

問題二:location匹配優先級

location = /code1/ { rewrite ^(.*)$ /code1/index.html break;}location ~ /code.* { rewrite ^(.*)$ /code3/index.html break;}location ^~ /code { rewrite ^(.*)$ /code2/index.html break;}

知識填坑:

=:進行普通字符精確匹配,完全匹配

^~:普通字符匹配,使用前綴匹配

~ /~*:表示執行一個正則匹配()

解決方法:

根據匹配找到最優匹配

優先級:完全匹配>正則匹配>前綴匹配

問題三:try_files使用

location / { try_files $uri $uri/ /index.html;}

解決方法:

按順序檢查文件是否存在

問題四:Nginx的alias和root區別

location /request_path/img/ { root /local_path/img/;}location /request_path/img/ { alias /local_path/img/;}

解決方法:

root設置,最終請求的路徑為/local_path/img/request_path/img/

alias設置,最終請求為/local_path/img/

問題五:通過多層代理,傳遞用戶真實IP

解決方法:

set x_real_ip=$remote_addr$x_real_ip=真實IP

性能優化問題

優化考慮點:

當前系統結構瓶頸,如觀察指標、壓力測試

了解業務模式,如接口業務類型、系統層次化結構

性能與安全

接口壓力測試工具:ab

安裝:yum install httpd-tools

使用:ab -n 2000 -c 20 http://127.0.0.1/

nginx關于系統的優化點:

網絡、系統、服務、程序、數據庫

控制文件句柄數量,文件句柄就是一個索引

CPU親和,使進程不會在處理器間頻繁遷移,減少性能損耗

vim /etc/nginx/nginx.confuser 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;}

nginx安全問題及防范策略

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 富民县| 汽车| 乐陵市| 宜州市| 施秉县| 军事| 扬中市| 长治县| 蒙山县| 祁门县| 咸丰县| 白山市| 绩溪县| 北票市| 台东市| 林周县| 垦利县| 长泰县| 苏尼特左旗| 蓬莱市| 弥渡县| 东乡县| 双柏县| 通化县| 上饶市| 株洲县| 乌什县| 邯郸县| 凌海市| 禹城市| 东宁县| 大兴区| 监利县| 鹤山市| 通城县| 克什克腾旗| 谢通门县| 金门县| 思南县| 兴海县| 霸州市|