Nginx 是一個很強大的高性能Web和反向代理服務器,它具備不少很是優越的特性:html
安裝包的下載地址:http://nginx.org/en/download.html
.nginx
# mkdir /gx | mount.cifs //192.168.100.99/gx /gx # yum install gcc gcc-c++ make pcre pcre-devel zlib-devel -y # tar xzvf /gxnginx-1.6.0.tar.gz -C /opt //解壓縮到opt目錄 # cd /opt/nginx-1.6.0/ ./configure \ --prefix=/usr/local/nginx \ --user=nginx \ --group=nginx \ --with-http_stub_status_module //功能模塊 統計日誌
.c++
# make && make install //編譯&&編譯安裝
# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/ //(軟鏈接 方便調用nginx命令) # nginx -t //查看是否安裝成功 # nginx //啓動Nginx 服務 # netstat -anpt | grep nginx //查看端口 # killall -1 nginx //重啓Nginx服務 #killall -3 nginx //關閉Nginx服務
# vim /usr/local/nginx/conf/nginx.conf pid logs/nginx.pid; //去#號 使下面腳本中路徑文件生成 vi /etc/init.d/nginx //建立服務腳本 #!/bin/bash # chkconfig: - 99 20 # description: Nginx Service Control Script PROG="/usr/local/nginx/sbin/nginx" PIDF="/usr/local/nginx/logs/nginx.pid" case "$1" in start) $PROG ;; stop) kill -s QUIT $(cat $PIDF) ;; restart) $0 stop $0 start ;; reload) kill -s HUP $(cat $PIDF) ;; *) echo "Usage: $0 {start|stop|restart|reload}" exit 1 esac exit 0 # chmod +x /etc/init.d/nginx # chkconfig --add nginx //添加爲系統服務 如今能夠使用service 控制Nginx服務了
全局配置vim
# vim /usr/local/nginx/conf/nginx.conf user nginx nginx; //去# 改用戶爲nginx worker_processes 1; //工做進程數量 ...... error_log logs/error.log info; //錯誤日誌文件
I/O事件配置瀏覽器
events { use epoll; //添加 使用epoll模型 worker_connections 1024; //每一個進程處理1024個鏈接 }
HTTP配置bash
http { include mime.types; //支持多媒體 default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$r equest" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; //訪問日誌位置 access_log logs/access.log main; sendfile on; //支持文件發送(下載) keepalive_timeout 65; //鏈接保持超時 server { //Web服務的監聽配置 listen 80; //監聽的端口 server_name www.benet.comt; //網站名稱 charset utf-8; //默認字符集 location / { root html; //網站根目錄的位置 index index.html index.htm; //默認首頁(索引頁) }
開啓訪問狀態統計服務器
跟上面配置後面 添加4行 location ~ /status { //訪問位置爲/status stub_status on; //打開狀態統計功能 access_log off; ////關閉此位置的日誌記錄 } # service nginx restart //重啓nginx服務 打開瀏覽器輸入服務器地址: 192.168.100.102 訪問Nginx的統計狀態 192.168.100.102/status