Nginx文件代理配置

文件代理配置

#user  nobody;
user root;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


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"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;
    
    
    server {
     listen       80 ;
     location ^~ / {
        alias /data/;
      }
    }

}

跨域配置部分:

# nginx file proxy
    upstream nginx-file-proxy {
        server 172.16.20.224:30333;
        server 172.16.20.225:30333;
    }
    server {
        listen       10333 ssl;
        server_name  dp-dev.zhito.com;

        ssl_certificate      /opt/nginx/ssl/scs1666119613720__.zhito.com_server.crt;
        ssl_certificate_key  /opt/nginx/ssl/scs1666119613720__.zhito.com_server.key;

        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;

        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;

        location ^~ / {
            # proxy_http_version 1.1;
          proxy_pass http://nginx-file-proxy;
          proxy_set_header Host $host;

          add_header 'Access-Control-Allow-Origin' * ;
          if ($request_filename ~* ^.*?\.(html|doc|pdf|zip|docx|txt|bag|rosbag|db3|mcap|ulg|ulbg)$) {
            add_header Content-Disposition attachment;
            add_header Content-Type application/octet-stream;
            #允许跨域请求的域,* 代表所有
            add_header 'Access-Control-Allow-Origin' *;
            #允许带上cookie请求
            add_header 'Access-Control-Allow-Credentials' 'true';
            #允许请求的方法,比如 GET/POST/PUT/DELETE
            add_header 'Access-Control-Allow-Methods' *;
            #允许请求的header
            add_header 'Access-Control-Allow-Headers' *;
            add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range,ETag,Content-Type,Accept-Ranges';
        }
        if ($request_method = 'OPTIONS') {
          #允许跨域请求的域,* 代表所有
 add_header 'Access-Control-Allow-Origin' *;
           #允许带上cookie请求
           add_header 'Access-Control-Allow-Credentials' 'true';
           #允许请求的方法,比如 GET/POST/PUT/DELETE
           add_header 'Access-Control-Allow-Methods' *;
           #允许请求的header
           add_header 'Access-Control-Allow-Headers' *;
           return 204;
        }
            proxy_http_version 1.1;
            sendfile on;   # 开启高效文件传输模式
            autoindex on;  # 开启目录文件列表
            autoindex_exact_size on;  # 显示出文件的确切大小,单位是bytes
            autoindex_localtime on;  # 显示的文件时间为文件的服务器时间
            charset utf-8,gbk;  # 避免中文乱码
            # client_max_body_size 0; 
      }
     }

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值