CentOS系統下最佳化Nginx伺服器配置(1/3)

來源:互聯網
上載者:User

Nginx是目前比較主流的WEB伺服器,也是比較主流而且強大的反向 ProxyWEB伺服器。自從搬家至騰訊雲端服務器上來後就一直使用Nginx作為本網站的WEB伺服器。下面就談談Nginx最佳化的一些東東:
編譯安裝Nginx具體過程這裡就不說了哈,下面是我的Nginx安裝目錄tree:
[root@VM_40_253_centos nginx]# tree ./
./
├── client_body_temp
├── conf
│   ├── fastcgi.conf
│   ├── fastcgi.conf.default
│   ├── fastcgi_params
│   ├── fastcgi_params.default
│   ├── koi-utf
│   ├── koi-win
│   ├── mime.types
│   ├── mime.types.default
│   ├── nginx.conf
│   ├── nginx.conf.default
│   ├── optimization.conf
│   ├── scgi_params
│   ├── scgi_params.default
│   ├── uwsgi_params
│   ├── uwsgi_params.default
│   └── win-utf
├── fastcgi_temp
├── html
│   ├── 50x.html
│   ├── index.html
│   ├── tz.php
│   └── tz.zip
├── logs
│   ├── access_2014-06-09.log
│   ├── access.log
│   ├── error.log
│   ├── newaccess.log
│   └── nginx.pid
├── proxy_temp
├── sbin
│   ├── cut-log.sh
│   └── nginx
├── scgi_temp
├── uwsgi_temp
└── vhosts
 ├── demo.iloxp.com.conf
 ├── iloxp.conf
 ├── kutea.conf
 ├── kutea.conf.bak
 └── kutea.conf.old

最佳化要點:

1.當然是禁用泛網域名稱解析了,啟用預設主控件—->指向403.啟用虛擬機器主機—–>指向自己的網站;
2.啟用gzip壓縮,以減少伺服器頻寬的輸出和提高訪問速度;
3.啟用緩衝;
4.存取控制,關閉不必要的訪問日誌記錄,例如來自 favicon.ico 的請求;
5.日誌管理,當然就是切割了,分日期記錄訪問日誌,便於我們分析;
6.最佳化php-fpm以及nginx的預設串連數量,減少502錯誤的出現,同時可以定期reload your php-fpm process。
OK ,就先寫這麼多吧。具體最佳化過程這裡就不說了。網上都是大把的了,對了,Google的gperftools對獨立nginx伺服器,小記憶體,還是沒什麼用處一樣,可以有也可以木有哈

例子

1.主設定檔最佳化:

 代碼如下 複製代碼

# vi /usr/local/nginx/conf/nginx.conf
-----------------------------------------
user nginx nginx;
worker_processes 8;
worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000;
error_log  /usr/local/nginx/logs/nginx_error.log  crit;
pid        /usr/local/nginx/logs/nginx.pid;
worker_rlimit_nofile 204800;
events
{
 use epoll;
 worker_connections 204800;
}
http {
      include       mime.types;
      default_type  application/octet-stream;
      log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                         '$status $body_bytes_sent "$http_referer" '
                         '"$http_user_agent" "$http_x_forwarded_for"';
      access_log  logs/access.log  main;
      charset  utf-8;
      server_names_hash_bucket_size 128;
      client_header_buffer_size 32k;
      large_client_header_buffers 4 32k;
      client_max_body_size 20m;
      sendfile on;
      tcp_nopush on;
      keepalive_timeout 60;
      fastcgi_cache_path /usr/local/nginx/fastcgi_cache levels=1:2
                         keys_zone=TEST:10m
                         inactive=5m;
      fastcgi_connect_timeout 300;
      fastcgi_send_timeout 300;
      fastcgi_read_timeout 300;
      fastcgi_buffer_size 64k;
      fastcgi_buffers 4 64k;
      fastcgi_busy_buffers_size 128k;
      fastcgi_temp_file_write_size 128k;
      open_file_cache max=204800 inactive=20s;
      open_file_cache_min_uses 1;
      open_file_cache_valid 30s;
      tcp_nodelay on;
      gzip on;
      gzip_min_length  1k;
      gzip_buffers     4 16k;
      gzip_http_version 1.0;
      gzip_comp_level 2;
      gzip_types       text/plain application/x-javascript text/css application/xml;
      gzip_vary on;
}
-----------------------------------------

首頁 1 2 3 末頁
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.