nginx配置文件详解

60 篇文章 0 订阅
54 篇文章 0 订阅


 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 
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值