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; 
      }
     }

你可能感兴趣的:(nginx)