濮阳杆衣贸易有限公司

主頁 > 知識庫 > nginx優(yōu)化的六點方法

nginx優(yōu)化的六點方法

熱門標簽:南昌外呼系統(tǒng)定制 海外工廠地圖標注 地圖標注小程序 南充電銷外呼系統(tǒng) 貴陽網(wǎng)絡外呼系統(tǒng)軟件 陜西辦理400電話 宿州外呼系統(tǒng)公司 信陽電銷外呼系統(tǒng)怎么樣 株洲電銷

一.優(yōu)化Nginx并發(fā)量

[root@proxy ~]# ab -n 2000 -c 2000 http://192.168.4.5/
Benchmarking 192.168.4.5 (be patient)
socket: Too many open files (24)    //提示打開文件數(shù)量過多

修改Nginx配置文件,增加并發(fā)量

[root@proxy ~]# vim /usr/local/nginx/conf/nginx.conf
.. ..
worker_processes 2;     //與CPU核心數(shù)量一致
events {
worker_connections 65535;  //每個worker最大并發(fā)連接數(shù)
use epoll;
}
.. ..
[root@proxy ~]# nginx -s reload

二.優(yōu)化Linux內(nèi)核參數(shù)(最大文件數(shù)量)

[root@proxy ~]# ulimit -a      //查看所有屬性值
[root@proxy ~]# ulimit -Hn 100000    //設置硬限制(臨時規(guī)則)
[root@proxy ~]# ulimit -Sn 100000    //設置軟限制(臨時規(guī)則)
[root@proxy ~]# vim /etc/security/limits.conf
 .. ..
*    soft nofile   100000
*    hard nofile   100000
#該配置文件分4列,分別如下:
#用戶或組 硬限制或軟限制 需要限制的項目 限制的值

優(yōu)化后測試服務器并發(fā)量

[root@proxy ~]# ab -n 2000 -c 2000 http://192.168.4.5/

三.優(yōu)化Nginx數(shù)據(jù)包頭緩存

[root@proxy ~]# cat lnmp_soft/buffer.sh 
#!/bin/bash
URL=http://192.168.4.5/index.html?
for i in {1..5000}
do
 URL=${URL}v$i=$i
done
curl $URL        //經(jīng)過5000次循環(huán)后,生成一個長的URL地址欄
[root@proxy ~]# ./buffer.sh
.. ..
<center><h1>414 Request-URI Too Large</h1></center>  //提示頭部信息過大

修改Nginx配置文件,增加數(shù)據(jù)包頭部緩存大小

[root@proxy ~]# vim /usr/local/nginx/conf/nginx.conf
.. ..
http {
client_header_buffer_size 1k;  //默認請求包頭信息的緩存 
large_client_header_buffers 4 4k;  //大請求包頭部信息的緩存?zhèn)€數(shù)與容量
.. ..
}
[root@proxy ~]# nginx -s reload

四.對頁面進行壓縮處理

[root@proxy ~]# cat /usr/local/nginx/conf/nginx.conf
http {
.. ..
gzip on;       //開啟壓縮
gzip_min_length 1000;    //小文件不壓縮
gzip_comp_level 4;    //壓縮比率
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
         //對特定文件壓縮,類型參考mime.types
.. ..

五.服務器內(nèi)存緩存

http { 
open_file_cache   max=2000 inactive=20s;
  open_file_cache_valid 60s;
  open_file_cache_min_uses 5;
  open_file_cache_errors off;
//設置服務器最大緩存2000個文件句柄,關閉20秒內(nèi)無請求的文件句柄
//文件句柄的有效時間是60秒,60秒后過期
//只有訪問次數(shù)超過5次會被緩存
}

六.瀏覽器本地緩存靜態(tài)數(shù)據(jù)

[root@proxy ~]# vim /usr/local/nginx/conf/nginx.conf
server {
  listen  80;
  server_name localhost;
  location / {
   root html;
   index index.html index.htm;
  }
location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ {
expires  30d;   //定義客戶端緩存時間為30天
}
}
[root@proxy ~]# cp /usr/share/backgrounds/day.jpg /usr/local/nginx/html
[root@proxy ~]# nginx -s reload

到此這篇關于nginx優(yōu)化的六點方法的文章就介紹到這了,更多相關nginx優(yōu)化內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

標簽:石嘴山 晉城 汕頭 開封 三明 拉薩 鄭州 玉林

巨人網(wǎng)絡通訊聲明:本文標題《nginx優(yōu)化的六點方法》,本文關鍵詞  nginx,優(yōu)化,的,六點,方法,;如發(fā)現(xiàn)本文內(nèi)容存在版權問題,煩請?zhí)峁┫嚓P信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《nginx優(yōu)化的六點方法》相關的同類信息!
  • 本頁收集關于nginx優(yōu)化的六點方法的相關信息資訊供網(wǎng)民參考!
  • 推薦文章
    沂南县| 汉阴县| 寻乌县| 民县| 木兰县| 新疆| 麦盖提县| 安国市| 成安县| 泸水县| 遂昌县| 射洪县| 安平县| 遂平县| 巧家县| 绍兴市| 新蔡县| 达孜县| 苗栗县| 旺苍县| 老河口市| 新宁县| 六盘水市| 山阳县| 石渠县| 汝阳县| 怀安县| 托克逊县| 西乌| 长岛县| 无极县| 招远市| 边坝县| 新竹县| 建宁县| 东兰县| 印江| 临城县| 隆尧县| 榆社县| 应城市|