nginx配置文件詳解



 1 user  www www; -- 用戶,組
 2 
 3 worker_processes auto; -- 自動啓動nginx進程
 4 
 5 error_log  /home/wwwlogs/nginx_error.log  crit; -- 錯誤日誌存放的位置,級別是crit,跟Aapche級別類似
 6 
 7 pid        /usr/local/nginx/logs/nginx.pid; -- Nginx的進程ID號存放的文件
 8 
 9 #Specifies the value for maximum file descriptors that can be opened by this process.
10 worker_rlimit_nofile 51200; --
11 
12 events -- 主要配置選項
13     {
14         use epoll; -- 支持Linux2.6以上內核,起到優化的作用
15         worker_connections 51200; -- 有效連接數的最大值,併發數,理論值
16         multi_accept on; -- 越多用戶連接,能起到優化作用
17     }
18 
19 http -- 設置相關協議
20     {
21         include       mime.types; -- 包含類型文件
22         default_type  application/octet-stream; -- 默認解析的文件的類型
23 
24         server_names_hash_bucket_size 128; -- 服務器和客戶端緩存的大小
25         client_header_buffer_size 32k;
26         large_client_header_buffers 4 32k;
27         client_max_body_size 50m;
28 
29         sendfile   on; -- 對服務器有優化作用
30         tcp_nopush on; -- 對服務器有優化作用
31 
32         keepalive_timeout 60; -- 有效連接時間爲60s,Apache默認300s
33 
34         tcp_nodelay on; -- 對服務器有優化作用
35 
36         fastcgi_connect_timeout 300;
37         fastcgi_send_timeout 300;
38         fastcgi_read_timeout 300;
39         fastcgi_buffer_size 64k;
40         fastcgi_buffers 4 64k;
41         fastcgi_busy_buffers_size 128k;
42         fastcgi_temp_file_write_size 256k;
43 
44         gzip on; -- 開啓壓縮功能
45         gzip_min_length  1k; --
46         gzip_buffers     4 16k;
47         gzip_http_version 1.1;
48         gzip_comp_level 2;
49         gzip_types     text/plain application/javascript application/x-javascript text/javascript text/css application/xml application/xml+rss;  --  要壓縮的靜態文件
50         gzip_vary on;
51         gzip_proxied   expired no-cache no-store private auth;
52         gzip_disable   "MSIE [1-6]\.";
53 
54         #limit_conn_zone $binary_remote_addr zone=perip:10m;
55         ##If enable limit_conn_zone,add "limit_conn perip 10;" to server section.
56 
57         server_tokens off;
58         #log format -- 設置日誌格式
59         log_format  access  '$remote_addr - $remote_user [$time_local] "$request" '
60              '$status $body_bytes_sent "$http_referer" '
61              '"$http_user_agent" $http_x_forwarded_for';
62                 access_log off;
63 
64 server
65     {
66         listen 80 default_server; -- 監聽端口80,default_server表示這個端口使用的是默認服務器
67         #listen [::]:80 default_server ipv6only=on; -- IPv6功能
68         server_name www.lnmp.org; -- 服務器域名
69         index index.html index.htm index.php; -- 索引的文件
70         root  /home/wwwroot/default; -- 網站根目錄


  autoindex on; -- 開啓列表頁顯示功能,
71 
72         #error_page   404   /404.html; -- 錯誤頁面
73         include enable-php.conf; -- 用來解析php的,php-fpm所指的配置文件
74 
75         location /nginx_status -- nginx_status狀態監控
76         {
77             stub_status on; -- 開啓,代表啓用nginx_status
78             access_log   off; -- 一般是給管理員用的,所以日誌是關閉的,使用方法:ip地址/nginx_status
79         }
80 
81         location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ -- 對網站圖片進行緩存
82         {
83             expires      30d; -- 緩存時間爲30天
84         }
85 
86         location ~ .*\.(js|css)?$ -- 對靜態文件進行緩存
87         {
88             expires      12h; -- 緩存時間爲12小時
89         }
90 
91         location ~ /\. -- 在當前根目錄下,除了文件文件的其他文件
92         {
93             deny all; -- 不做任何處理
94         }
95 
96         access_log  /home/wwwlogs/access.log  access; -- 訪問日誌的位置
97     }
98 include vhost/*.conf;
99 }
100 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章