關閉→
當前位置:知科普>IT科技>nginx配置檔案詳解

nginx配置檔案詳解

知科普 人氣:2.53W

產品型號:Thinkpad E15

系統版本:centos8

nginx配置檔案詳解

nginx配置檔案詳解

#定義Nginx執行的使用者和使用者組

user nginx nginx;

#nginx程序數,建議設定為等於CPU總核心數。

worker_processes 8;

#全域性錯誤日誌定義型別,[ debug | info | notice | warn | error | crit ]

error_log /var/log/nginx/error.log info;

#程序檔案

pid /var/run/nginx.pid;

#一個nginx程序開啟的最多檔案描述符數目,理論值應該是最多開啟檔案數(系統的值ulimit -n)與nginx程序數相除,但是nginx分配請求並不均勻,所以建議與ulimit -n的值保持一致。

worker_rlimit_nofile 65535;

#設定http伺服器

http

{

include mime.types; #副檔名與檔案型別對映表

default_type application/octet-stream; #預設檔案型別

#charset utf-8; #預設編碼

server_names_hash_bucket_size 128; #伺服器名字的hash表大小

client_header_buffer_size 32k; #上傳檔案大小限制

large_client_header_buffers 4 64k; #設定請求緩

client_max_body_size 8m; #設定請求緩

autoindex on; #開啟目錄列表訪問,合適下載伺服器,預設關閉。

tcp_nopush on; #防止網路阻塞

tcp_nodelay on; #防止網路阻塞

keepalive_timeout 120; #長連線超時時間,單位是秒

#gzip模組設定

gzip on; #開啟gzip壓縮輸出

gzip_min_length 1k; #最小壓縮檔案大小

gzip_buffers 4 16k; #壓縮緩衝區

gzip_http_version 1.0; #壓縮版本(預設1.1,前端如果是squid2.5請使用1.0)

gzip_comp_level 2; #壓縮等級

gzip_vary on;

#limit_zone crawler $binary_remote_addr 10m; #開啟限制IP連線數的時候需要使用

#虛擬主機的配置

server

{

#監聽埠

listen 80;

#域名可以有多個,用空格隔開

server_name www.ha97.com ha97.com;

index index.html index.htm index.php;

root /data/www/ha97;

location ~ .*.(php|php5)?$

{

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

include fastcgi.conf;

}

#圖片快取時間設定

location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$

{

expires 10d;

}

#JS和CSS快取時間設定

location ~ .*.(js|css)?$

{

expires 1h;

}

#定義本虛擬主機的訪問日誌

access_log /var/log/nginx/ha97access.log access;

#對 “/” 啟用反向代理

location / {

proxy_pass http://127.0.0.1:88;

proxy_redirect off;

proxy_set_header X-Real-IP $remote_addr;

#後端的Web伺服器可以通過X-Forwarded-For獲取使用者真實IP

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

TAG標籤:#nginx #配置檔案 #