關閉→
當前位置:知科普>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 #配置文件 #