WIKI使用導(dǎo)航
站長(zhǎng)百科導(dǎo)航
站長(zhǎng)專題
- 網(wǎng)站推廣
- 網(wǎng)站程序
- 網(wǎng)站賺錢
- 虛擬主機(jī)
- cPanel
- 網(wǎng)址導(dǎo)航專題
- 云計(jì)算
- 微博營(yíng)銷
- 虛擬主機(jī)管理系統(tǒng)
- 開(kāi)放平臺(tái)
- WIKI程序與應(yīng)用
- 美國(guó)十大主機(jī)
Nginx安裝配置
來(lái)自站長(zhǎng)百科
安裝[ ]
Nginx發(fā)音為[engine x],是由俄羅斯人Igor Sysoev建立的項(xiàng)目,基于BSD許可。據(jù)說(shuō)他當(dāng)初是F5的成員之一,英文主頁(yè):http://nginx.net。俄羅斯的一些大網(wǎng)站已經(jīng)使用它超過(guò)兩年多了,一直表現(xiàn)不凡。
在這里,需要說(shuō)明一下,由于Nginx的配置文件中用到正則,所以需要pcre模塊的支持。 可以到這里下載一個(gè)http://www.pcre.org/
解壓再cp到和nginx同一個(gè)目錄上
Nginx的編譯參數(shù)如下:
tar zxvf nginx-0.5.33.tar.gz cd nginx-0.5.33/ ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-pcre=../pcre-6.6 make && make install
修改配置文件 /usr/local/nginx/conf/nginx.conf[ ]
以下是我的 nginx.conf 內(nèi)容,僅供參考:
#運(yùn)行用戶 user nobody nobody; #啟動(dòng)進(jìn)程 一般和cpu數(shù)對(duì)等,壓力大的也可以調(diào)高點(diǎn) worker_processes 2; #全局錯(cuò)誤日志及PID文件 error_log logs/error.log notice; pid logs/nginx.pid; #工作模式及連接數(shù)上限 events { use epoll; worker_connections 1024; } #設(shè)定http服務(wù)器,利用它的反向代理功能提供負(fù)載均衡支持 http { #設(shè)定mime類型 include conf/mime.types; default_type application/octet-stream; #設(shè)定日志格式 log_format main '$remote_addr - $remote_user [$time_local] ' '"$request" $status $bytes_sent ' '"$http_referer" "$http_user_agent" ' '"$gzip_ratio"'; log_format download '$remote_addr - $remote_user [$time_local] ' '"$request" $status $bytes_sent ' '"$http_referer" "$http_user_agent" ' '"$http_range" "$sent_http_content_range"'; #設(shè)定請(qǐng)求緩沖 client_header_buffer_size 1k; large_client_header_buffers 4 4k; #開(kāi)啟gzip模塊 gzip on; gzip_min_length 1100; gzip_buffers 4 8k; gzip_types text/plain; output_buffers 1 32k; postpone_output 1460; #設(shè)定access log access_log logs/access.log main; client_header_timeout 3m; client_body_timeout 3m; send_timeout 3m; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; #設(shè)定負(fù)載均衡的服務(wù)器列表 upstream mysvr { #weigth參數(shù)表示權(quán)值,權(quán)值越高被分配到的幾率越大 #本機(jī)上的Squid開(kāi)啟3128端口 server 192.168.8.1:3128 weight=5; server 192.168.8.2:80 weight=1; server 192.168.8.3:80 weight=6; } #設(shè)定虛擬主機(jī) server { listen 80; server_name 192.168.8.1 www.yejr.com; charset gb2312; #設(shè)定本虛擬主機(jī)的訪問(wèn)日志 access_log logs/www.yejr.com.access.log main; #如果訪問(wèn) /img/*, /js/*, /css/* 資源,則直接取本地文件,不通過(guò)squid #如果這些文件較多,不推薦這種方式,因?yàn)橥ㄟ^(guò)squid的緩存效果更好 location ~ ^/(img|js|css)/ { root /data3/Html; expires 24h; } #對(duì) "/" 啟用負(fù)載均衡 location / { proxy_pass http://mysvr; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; client_max_body_size 10m; client_body_buffer_size 128k; proxy_connect_timeout 90; proxy_send_timeout 90; proxy_read_timeout 90; proxy_buffer_size 4k; proxy_buffers 4 32k; proxy_busy_buffers_size 64k; proxy_temp_file_write_size 64k; } #設(shè)定查看Nginx狀態(tài)的地址 location /NginxStatus { stub_status on; access_log on; auth_basic "NginxStatus"; auth_basic_user_file conf/htpasswd; } }
}
運(yùn)行以下命令檢測(cè)配置文件是否無(wú)誤:
# /usr/local/nginx/sbin/nginx -t //Debug 配置文件的關(guān)鍵命令需要重點(diǎn)撐握. 2008/12/16 09:08:35 [info] 28412#0: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok 2008/12/16 09:08:35 [info] 28412#0: the configuration file /usr/local/nginx/conf/nginx.conf was tested successfully
如果沒(méi)有報(bào)錯(cuò),那么就可以開(kāi)始運(yùn)行Nginx了,執(zhí)行以下命令即可:
# /usr/local/nginx/sbin/nginx
備注:conf/htpasswd 文件的內(nèi)容用Apache提供的 htpasswd 工具來(lái)產(chǎn)生即可,內(nèi)容大致如下:
查看 Nginx 運(yùn)行狀態(tài)[ ]
輸入地址 http://192.168.8.1/NginxStatus/,輸入驗(yàn)證帳號(hào)密碼,即可看到類似如下內(nèi)容:
Active connections: 328 server accepts handled requests 9309 8982 28890 Reading: 1 Writing: 3 Waiting: 324
第一行表示目前活躍的連接數(shù) 第三行的第三個(gè)數(shù)字表示Nginx運(yùn)行到當(dāng)前時(shí)間接受到的總請(qǐng)求數(shù),如果快達(dá)到了上限,就需要加大上限值了。 第四行是當(dāng)前處理的請(qǐng)求數(shù)