1.ngnix.conf的配置結(jié)構(gòu)
2.部分配置文件說明
#worker進(jìn)程可操作的用戶
#user nobody;
#設(shè)置worker的個數(shù)
worker_processes 1;
#錯誤日志
#error_log logs/error.log;
#日志級別 debug info notice warn error crit
#error_log logs/error.log notice;
#error_log logs/error.log info;
#nginx的進(jìn)程號
#pid logs/nginx.pid;
#事件處理
events {
#操作模式,默認(rèn)使用epoll(linux系統(tǒng)使用)
use epoll;
#設(shè)置每個worker的客戶端最大連接數(shù)
worker_connections 1024;
}
#相關(guān)網(wǎng)絡(luò)傳輸模塊
http {
#導(dǎo)入的外部指令(外部文件)mime.types在conf目錄下
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"';
#http請求的日志文件
#access_log logs/access.log main;
#打開文件傳輸
sendfile on;
#與sendfile一起使用搀绣,但數(shù)據(jù)包累計到一定程度以后再去發(fā)送
#tcp_nopush on;
#keepalive_timeout 0;
#http保持連接的狀態(tài)超時時間(單位秒)
keepalive_timeout 65;
#開啟內(nèi)容傳輸壓縮
#gzip on;
#限制最小壓縮链患,小于1字節(jié)的文件不會壓縮
#gzip_min_length 1
#定義壓縮的級別(文件越大,壓縮越多,但是cpu占用越高)
#gzip_comp_level 3
#定義壓縮文件的類型
gzip_type gzip_types text/plain application/javascript application/x-javascript text/css applicatio n/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png application/ json;|
#服務(wù)器配置
server {
#監(jiān)聽的端口
listen 80;
#監(jiān)聽的域名
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
# /匹配的請求地址
location / {
#影射的文件夾览闰,html表示conf的同級目錄的html文件夾
root html;
#指定默認(rèn)的首頁
index index.html index.htm;
}
#默認(rèn)的配置
location / {
#影射的文件夾,html表示conf的同級目錄的html文件夾
root html;
#指定默認(rèn)的首頁
index index.html index.htm;
}
#當(dāng)用戶請求 /test压鉴,nginx會自動拼接到/home后面锻拘,即訪問/home/test路徑
location /test {
#影射的文件夾击蹲,html表示conf的同級目錄的html文件夾
root /home;
}
#alias來設(shè)置別名婉宰,當(dāng)用戶訪問/static,nginx影射到 /home/static路徑中
location /static {
#影射的文件夾类咧,html表示conf的同級目錄的html文件夾
alias /home/static;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
# 錯誤頁面配置
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
3.配置重新加載才生效
進(jìn)入sbin目錄蟹腾,輸入如下路徑
./nginx -s reload