nginx 配置文件下载及在线浏览
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了nginx 配置文件下载及在线浏览相关的知识,希望对你有一定的参考价值。
nginx 配置文件下载及在线浏览
1.主配置文件
# vim nginx.conf user nginx; worker_processes 2; worker_rlimit_nofile 65535; error_log /usr/local/nginx/logs/error.log warn; pid /usr/local/nginx/logs/nginx.pid; events { use epoll; worker_connections 4096; multi_accept on; } http { include mime.types; default_type application/octet-stream; log_format main ‘$remote_addr - $remote_user [$time_local] "$request" ‘ ‘$status $body_bytes_sent "$http_referer" ‘ ‘"$http_user_agent" $http_x_forwarded_for‘; server_tokens off; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; client_header_timeout 20; client_body_timeout 20; send_timeout 30; gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.0; gzip_comp_level 4; gzip_types text/plain application/x-javascript text/css application/xml; gzip_vary on; include fastcgi_params; include /usr/local/nginx/conf/vhosts/*.conf; }
2.下载配置文件
# vim toms-file.conf server { listen 80; server_name 10.1.1.222; access_log /data/logs/file_seedeer.log main; index index.html index.htm index.php; root /pdf_data/pdf; access_log_bypass_if ($remote_addr ~* ‘^100.97‘) and; access_log_bypass_if ($request ~* "HEAD / HTTP/1.0"); access_log /usr/local/nginx/logs/api_toms.log; charset utf-8; location / { autoindex on; autoindex_exact_size on; autoindex_localtime on; if ($request_filename ~* ^.*?\.(txt|doc|pdf|rar|gz|zip|docx|exe|xlsx|ppt|pptx)$){ add_header Content-Disposition: ‘attachment;‘; } } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|mp3)$ { expires 30d; } location ~ .*\.(js|css)?$ { expires 30d; } }
3.说明
location / { autoindex on; autoindex_exact_size on; autoindex_localtime on; if ($request_filename ~* ^.*?\.(txt|doc|pdf|rar|gz|zip|docx|exe|xlsx|ppt|pptx)$){ add_header Content-Disposition: ‘attachment;‘; } }
以上配置允许的文件格式后缀,文件可以打开,可以下载。
charset utf-8; //支持的字符集,不然汉字会乱码
4.测试文件预览及下载
本文出自 “深呼吸再出击” 博客,请务必保留此出处http://ckl893.blog.51cto.com/8827818/1926623
以上是关于nginx 配置文件下载及在线浏览的主要内容,如果未能解决你的问题,请参考以下文章
全栈编程系列SpringBoot整合Shiro(含KickoutSessionControlFilter并发在线人数控制以及不生效问题配置启动异常No SecurityManager...)(代码片段