nginx默認配置文件 nginx.conf 介紹:
全局配置 | user nginx; | 設置nginx服務的系統使用用戶 |
worker_processes 1; | 工作進程數(建議和CPU核心數保持一致) | |
error_log /var/log/nginx/error.log warn; | 錯誤日志。 'warn'代表級別 | |
pid /var/run/nginx.pid; | 服務啟動時候的pid | |
events { | ||
worker_connections 1024; | 每個進程允許最大連接數(一般1W左右可滿足大部分企業需求) | |
} | ||
http { | ||
include /etc/nginx/mime.types; | ||
default_type application/octet-stream; | ||
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' | 日志格式,名字為'main',后面的"$XXX"為日志字段 | |
'$status $body_bytes_sent "$http_referer" ' | $remote_addr:用戶IP、$request:請求的方法、$http_referer:referer值 | |
'"$http_user_agent" "$http_x_forwarded_for"'; | ||
access_log /var/log/nginx/access.log main; | 訪問日志路徑。'main'代表相應log_format名字 | |
sendfile on; | 這個可以提高讀取靜態文件效率。 開啟它之后用戶訪問靜態文件時將直接通過系統內核將文件放入socket,而不是打開文件再將數據放入socket | |
#tcp_nopush on; | senffile開啟的情況下,提高數據包的傳輸效率。 即:攢夠一定量的包再一起發送,而不是來一個包發一個包 | |
keepalive_timeout 65; | ||
#gzip on; | 是否支持壓縮 | |
include /etc/nginx/conf.d/*.conf; | 這句話就將其他配置文件都包含進來了 | |
} |
|
nginx默認配置文件 default.conf介紹:
server { | 子server,可以理解為一個server為一台虛擬服務器 |
listen 80; | 偵聽端口 |
server_name localhost; | 域名 當一台nginx服務器提供多個域名服務且端口都一樣時可以根據用戶訪問的域名來判斷是否應該使用這個server(可以理解為7層的路由),如果用戶訪問的是app.cctv.com,而這里配的是tv.cctv.com則不會使用該server。 |
#charset koi8-r; | |
#access_log /var/log/nginx/host.access.log main; | |
location / { | 一個server里面可以有多個location。‘/’代表不管訪問主頁還是子路徑都進入這個location進行訪問 |
root /usr/share/nginx/html; | ‘root’是存放首頁的路徑。 |
index index.html index.htm; | ‘index’用來指定首頁文件,首選index.html,如果沒有找到就選index.htm(類似DNS的主備)。 |
} | |
#error_page 404 /404.html; | |
# redirect server error pages to the static page /50x.html | |
# | |
error_page 500 502 503 504 /50x.html; | 如果狀態碼為500 502 503 504則返回/50x.html頁面 |
location = /50x.html { | 定義50x.html的路徑 |
root /usr/share/nginx/html; | |
} | |
# proxy the PHP scripts to Apache listening on 127.0.0.1:80 | |
# | |
#location ~ \.php$ { | |
# proxy_pass http://127.0.0.1; | |
#} | |
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 | |
# | |
#location ~ \.php$ { | |
# root html; | |
# fastcgi_pass 127.0.0.1:9000; | |
# fastcgi_index index.php; | |
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; | |
# include fastcgi_params; | |
#} | |
# deny access to .htaccess files, if Apache's document root | |
# concurs with nginx's one | |
# | |
#location ~ /\.ht { | |
# deny all; | |
#} | |
} |