user nginx; #代表使用的用户 worker_processes auto; #工作衍生进程数,一般代表系统cpu核数一到两倍最好 error_log /var/log/nginx/error.log; #错误日至文件 pid /run/nginx.pid; #设置pid存放路径,pid是控制系统中的一个重要的控制文件 # Load dynamic modules. See /usr/share/nginx/README.dynamic. include /usr/share/nginx/modules/*.conf; #设置最大链接数 events { worker_connections 1024; } #网页相关配置 http { #gzip on;开启gizp压缩,设置用户访问时,是否开启压缩功能,提高文件数据传输速度 #chatset gb2312;设置字符编码 log_format main ‘$remote_addr - $remote_user [$time_local] "$request" ‘ ‘$status $body_bytes_sent "$http_referer" ‘ ‘"$http_user_agent" "$http_x_forwarded_for"‘; access_log /var/log/nginx/access.log main; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; include /etc/nginx/mime.types; default_type application/octet-stream; # Load modular configuration files from the /etc/nginx/conf.d directory. # See http://nginx.org/en/docs/ngx_core_module.html#include # for more information. include /etc/nginx/conf.d/*.conf; server { listen 80 default_server;#nginx默认访问端口 server_name _; #root /usr/share/nginx/html; index index.html index.php; root /var/www/html; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location / { } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } } server { listen 80; #需要监听的端口 server_name xxx.xxx; #域名 index index.html index.php; #默认访问文件 root /var/www/xxx; #虚拟主机目录 # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location / { } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } } # Settings for a TLS enabled server. # # server { # listen 443 ssl http2 default_server; # listen [::]:443 ssl http2 default_server; # server_name _; # root /usr/share/nginx/html; # # ssl_certificate "/etc/pki/nginx/server.crt"; # ssl_certificate_key "/etc/pki/nginx/private/server.key"; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 10m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # # # Load configuration files for the default server block. # include /etc/nginx/default.d/*.conf; # # location / { # } # # error_page 404 /404.html; # location = /40x.html { # } # # error_page 500 502 503 504 /50x.html; # location = /50x.html { # } # } }
gzip on;#开启gizp压缩,设置用户访问时,是否开启压缩功能,提高文件数据传输速度 gzip_min_length 1k;#需要压缩的文件最小1k gzip_buffers 4 16k;#申请内存大小来存储压缩的文件,4个16k的数据流 gzip_http_version 1.1;#gzip技术支持的http版本1.1 #以上为最常用的配置 gzip_vary on;#首先判断客户端是否支持gzip压缩技术,不支持的不就不进行gzip技术压缩
开启目录访问在对应的sever的location 中添加autoindex on;即可
原文:http://www.cnblogs.com/jackylee92/p/6258055.html