Nginx_配置

user www-data;
worker_processes auto;
pid /run/nginx.pid;

events {
    worker_connections 768;
    # multi_accept on;
}

http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ##
    # SSL Settings
    ##

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;
    gzip_disable "msie6";
    #gzip 压缩文件类型
        gzip_types text/plain application/x-javascript application/javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;

    # gzip_vary on;
    # gzip_proxied any;
    # gzip_comp_level 6;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;



#mail {
#    # See sample authentication script at:
#    # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
# 
#    # auth_http localhost/auth.php;
#    # pop3_capabilities "TOP" "USER";
#    # imap_capabilities "IMAP4rev1" "UIDPLUS";
# 
#    server {
#        listen     localhost:110;
#        protocol   pop3;
#        proxy      on;
#    }
# 
#    server {
#        listen     localhost:143;
#        protocol   imap;
#        proxy      on;
#    }
#}
server {
    listen       2021;
    server_name  localhost; # 修改为docker服务宿主机的ip

    location / {
  
        root   /usr/share/nginx/html;#定义服务器的默认网站根目录位置
        index  index.html index.htm;#定义首页索引文件的名称
        try_files $uri $uri/ /index.html =404; #单页应用的逻辑是不存在的请求资源全部交由index.html处理 ,vue 在 history情况下会出现404,就加上这个
}    # 定义错误提示页面 error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } }


我Nginx配置下载地址:
location /download {
alias usr/share/nginx/html/cc/temp
}
这样我请求www.xxx.com/download/1.png没问题
但是:
如果我文件又用子文件夹区分呢?
比如:
/usr/share/nginx/html/cc/temp/images/1.png
/usr/share/nginx/html/cc/temp/ppts/1.ppt
/usr/share/nginx/html/cc/temp/excels/20221228/1.excel
/usr/share/nginx/html/cc/temp/excels/20221228/2.excel
/usr/share/nginx/html/cc/temp/excels/20221227/2.excel
/usr/share/nginx/html/cc/temp/excels/20221226/3.excel
/usr/share/nginx/html/cc/temp/..../.../....xxxx

解决办法:

location ~^/download/data($|/.*) {
  alias /data/html/dh/dist/static$1;

  autoindex on; # 开启目录文件列表

  autoindex_exact_size on; # 显示出文件的确切大小,单位是bytes

  autoindex_localtime on; # 显示的文件时间为文件的服务器时间

  charset utf-8,gbk; # 避免中文乱码

}

 

 

posted @ 2021-02-18 18:56  彪悍的代码不需要注释  阅读(109)  评论(1编辑  收藏  举报
39
0