1.ngnix.conf的配置結構
2.部分配置文件說明
#worker進程可操作的用戶
#user nobody;
#設置worker的個數
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的進程號
#pid logs/nginx.pid;
#事件處理
events {
#操作模式,默認使用epoll(linux系統使用)
use epoll;
#設置每個worker的客戶端最大連接數
worker_connections 1024;
}
#相關網絡傳輸模塊
http {
#導入的外部指令(外部文件)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一起使用,但數據包累計到一定程度以後再去發送
#tcp_nopush on;
#keepalive_timeout 0;
#http保持連接的狀態超時時間(單位秒)
keepalive_timeout 65;
#開啓內容傳輸壓縮
#gzip on;
#限制最小壓縮,小於1字節的文件不會壓縮
#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;|
#服務器配置
server {
#監聽的端口
listen 80;
#監聽的域名
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
#默認的配置
location / {
#影射的文件夾,html表示conf的同級目錄的html文件夾
root html;
#指定默認的首頁
index index.html index.htm;
}
#當用戶請求 /test,nginx會自動拼接到/home後面,即訪問/home/test路徑
location /test {
#影射的文件夾,html表示conf的同級目錄的html文件夾
root /home;
}
#alias來設置別名,當用戶訪問/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.配置重新加載才生效
進入sbin目錄,輸入如下路徑
./nginx -s reload