Nginx是一個(gè)高性能的HTTP服務(wù)器和反向代理服務(wù)器,通常在實(shí)現(xiàn)高并發(fā)場(chǎng)景中扮演重要的角色。尤其適合承載靜態(tài)資源的訪問。相關(guān)數(shù)據(jù)顯示,Nginx最大能抗住5萬并發(fā)。
本篇文章,從以下三個(gè)方面,記錄Nginx的日常使用方法。
- 靜態(tài)資源能力
- 虛擬主機(jī)
- 反向代理,負(fù)載均衡
為了方便演示,我們直接在windows上進(jìn)行操作。在windows上安裝Nginx,可參閱相關(guān)文檔。
起步
安裝好之后,我們進(jìn)入到nginx根目錄,輸入:
start nginx
之后,我們?cè)L問localhost:80,若出現(xiàn)nginx相關(guān)信息,則說明nginx正常啟動(dòng)。
配置文件
Nginx的配置文件為/conf/nginx.conf,刨去注釋,我們先來簡(jiǎn)單認(rèn)識(shí)一下:
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}