• Nginx 配置浏览Linux 系统目录并下载文件


    准备工作:

      安装编译工具及库文件: yum -y install make zlib zlib-devel gcc-c++ libtool  openssl openssl-devel

      安装PCRE(目的是让Nginx支持Rewrite功能): 

        下载安装包:wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz

        解压安装包:tar -zxvf pcre-8.35.tar.gz

        进入安装目录编译文件:./configure make && make install

        查看版本号(能查看说明成功): pcre-config --version

    准备工作到此为止下面是Nginx的配置(Nginx的下载和安装不在此列出):

      1. 进入Nginx的安装目录,备份配置文件:  cp /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx_beifen.conf

      2. 编辑配置文件删除下面默认的server配置,如下: 

        

    user root;
    worker_processes auto;
    
    error_log /data/wwwlogs/error_nginx.log crit;
    pid /usr/local/nginx/logs/nginx.pid;
    worker_rlimit_nofile 51200;
    
    events {
      use epoll;
      worker_connections 51200;
      multi_accept on;
    }
    
    http {
      include mime.types;
      default_type application/octet-stream;
      server_names_hash_bucket_size 128;
      client_header_buffer_size 32k;
      large_client_header_buffers 4 32k;
      client_max_body_size 1024m;
      client_body_buffer_size 10m;
      sendfile on;
      tcp_nopush on;
      keepalive_timeout 120;
      server_tokens off;
      tcp_nodelay on;
    
      fastcgi_connect_timeout 300;
      fastcgi_send_timeout 300;
      fastcgi_read_timeout 300;
      fastcgi_buffer_size 64k;
      fastcgi_buffers 4 64k;
      fastcgi_busy_buffers_size 128k;
      fastcgi_temp_file_write_size 128k;
      fastcgi_intercept_errors on;
    
      #Gzip Compression
      gzip on;
      gzip_buffers 16 8k;
      gzip_comp_level 6;
      gzip_http_version 1.1;
      gzip_min_length 256;
      gzip_proxied any;
      gzip_vary on;
      gzip_types
        text/xml application/xml application/atom+xml application/rss+xml application/xhtml+xml image/svg+xml
        text/javascript application/javascript application/x-javascript
        text/x-json application/json application/x-web-app-manifest+json
        text/css text/plain text/x-component
        font/opentype application/x-font-ttf application/vnd.ms-fontobject
        image/x-icon;
      gzip_disable "MSIE [1-6].(?!.*SV1)";
    
      ##Brotli Compression
      #brotli on;
      #brotli_comp_level 6;
      #brotli_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript image/svg+xml;
    
      ##If you have a lot of static files to serve through Nginx then caching of the files' metadata (not the actual files' contents) can save some latency.
      #open_file_cache max=1000 inactive=20s;
      #open_file_cache_valid 30s;
      #open_file_cache_min_uses 2;
      #open_file_cache_errors on;
    
    ######################## default ############################
    ########################## vhost #############################
      include vhost/*.conf;
    }

    在nginx的配置文件的文件夹 conf 下创建vhost 文件夹并创建配置文件 host.conf (名称随意),配置内容如下(重点)

    server {
        listen 80; # 监听端口
        server_name 39.99.247.19; # 域名或IP
        access_log /data/wwwlogs/access_nginx.log combined;
        root /data/wwwroot/default;
        index index.html index.htm index.php;
        #error_page 404 /404.html;
        #error_page 502 /502.html;
      # 配置完这个服务职能在浏览器中浏览相关目录,但不能下载文件,配置完下面服务之后才能点击文件下载。 location
    /download { alias /root/workspace/installpackage; #文件所在的文件夹 autoindex on; autoindex_exact_size off; autoindex_localtime on; charset utf-8,gbk; }   # 配置完这个 点击文件就能下载了 location ~ ^/root/workspace/installpackage/(.*)$ { # 当访问该文件夹中任意结尾的文件时把header头修改为下载,这样浏览器就知道是要下载而不是打开路径了 add_header Content-Disposition "attachment; filename=$1"; } }

    至此,配置完毕,输入ip:80/download就可以访问目录了,点击文件就能下载了

  • 相关阅读:
    Three.js中引入dat.gui库实现界面组件控制动画速度变量
    Three.js中使用requestAnimationFrame方法实现立方体转动和小球跳动的动画
    Windows下使用Java API操作HDFS的常用方法
    Windows下配置Hadoop的Java开发环境以及用Java API操作HDFS
    HDFS的访问方式之HDFS shell的常用命令
    CentOS7上搭建Hadoop集群(入门级)
    CentOS7中怎样安装JDK与配置环境变量
    【2021-08-05】哪怕天踏下来,也要当被子盖
    【2021-08-04】连岳摘抄
    【2021-08-03】里程碑
  • 原文地址:https://www.cnblogs.com/qiaoyutao/p/12804015.html
Copyright © 2020-2023  润新知