server{
        listen 0.0.0.0:443 ssl;
        listen [::]:443  ssl;

        root /var/www/html/update;
        server_name updatetencent.webrtc.win ali.webrtc.win updateoss.webrtc.win firmware.webrtc.win;
        #server_name _;

        ssl on;
        ssl_certificate /etc/pear/pear_httpd/ca_certs/updateoss.webrtc.win/webrtc.win.cer;
        ssl_certificate_key /etc/pear/pear_httpd/ca_certs/updateoss.webrtc.win/webrtc.win.key;
        ssl_client_certificate /etc/pear/pear_httpd/ca_certs/updateoss.webrtc.win/webrtc.win.cer;
        ssl_ciphers 'ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256';
        ssl_protocols  TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;
        ssl_session_cache  builtin:1000  shared:SSL:10m;
        ssl_session_timeout  5m;
        ssl_stapling on;
        ssl_stapling_verify on;

        location / {
                limit_rate 500k; # speed is 2000kB/S

                add_header 'Access-Control-Allow-Origin' '*';
                add_header 'Access-Control-Allow-Credentials' 'true';
                add_header 'Access-Control-Allow-Methods' 'GET, POST,OPTIONS,  HEAD, DELETE, PUT';
                add_header 'Access-Control-Allow-Headers' 'Range,Host';
                add_header 'Access-Control-Expose-Headers' 'X-PEAR-ARGS,Content-Length,Content-Range';
                add_header 'X-PEAR-ARGS' $args;
                if ($request_method = 'OPTIONS') {
                        add_header 'Access-Control-Allow-Origin' '*';
                        add_header 'Access-Control-Allow-Credentials' 'true';
                        add_header 'Access-Control-Allow-Methods' 'GET, POST,OPTIONS,  HEAD, DELETE, PUT';
                        add_header 'Access-Control-Allow-Headers' 'Range,Host';
                        return 200;
                }
        }

	location /upload {
                add_header Access-Control-Allow-Headers "Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With";
                add_header Access-Control-Allow-Methods "GET,POST,PUT,DELETE,OPTIONS";
                add_header Content-Type "application/json";
		add_header 'Access-Control-Allow-Origin' '*';
                # Pass altered request body to this location
                upload_pass @test;

                #client_max_body_size 1m;
                # Store files to this directory
                # The directory is hashed, subdirectories 0 1 2 3 4 5 6 7 8 9 should exist
                upload_store /tmp 1;
                client_max_body_size 10000m;
                # Allow uploaded files to be read only by user
                upload_store_access user:r;

                # Set specified fields in request body
                upload_set_form_field $upload_field_name.name "$upload_file_name";
                upload_set_form_field $upload_field_name.content_type "$upload_content_type";
                upload_set_form_field $upload_field_name.path "$upload_tmp_path";

                # Inform backend about hash and size of a file
                upload_aggregate_form_field "$upload_field_name.md5" "$upload_file_md5";
                upload_aggregate_form_field "$upload_field_name.size" "$upload_file_size";

                upload_pass_form_field "^submit$|^description$";

                upload_cleanup 400 404 499 500-505;

        }


        # Pass altered request body to a backend
        location @test {
                proxy_pass   http://localhost:8081;
        }

}


#server{
#        listen 80;
#        listen [::]:80;
#
#        root /var/www/html/update;
#        server_name updatetencent.webrtc.win ali.webrtc.win updateoss.webrtc.win;
#        #server_name _;
#    	autoindex on; #开启目录浏览
#    	autoindex_format html; #以html风格将目录展示在浏览器中
#    	autoindex_exact_size off; #切换为 off 后，以可读的方式显示文件大小，单位为 $
#    	autoindex_localtime on; #以服务器的文件时间作为显示的时间
#    	charset utf-8; 
#        location / {
#                #limit_rate 500k; # speed is 2000kB/S
#
#                add_header 'Access-Control-Allow-Origin' '*';
#                add_header 'Access-Control-Allow-Credentials' 'true';
#                add_header 'Access-Control-Allow-Methods' 'GET, POST,OPTIONS,  HEAD, DELETE, PUT';
#                add_header 'Access-Control-Allow-Headers' 'Range,Host';
#                add_header 'Access-Control-Expose-Headers' 'X-PEAR-ARGS,Content-Length,Content-Range';
#                add_header 'X-PEAR-ARGS' $args;
#                if ($request_method = 'OPTIONS') {
#                        add_header 'Access-Control-Allow-Origin' '*';
#                        add_header 'Access-Control-Allow-Credentials' 'true';
#                        add_header 'Access-Control-Allow-Methods' 'GET, POST,OPTIONS,  HEAD, DELETE, PUT';
#                        add_header 'Access-Control-Allow-Headers' 'Range,Host';
#                        return 200;
#                }
#        }
#}


server{
        listen 80;
        listen [::]:80;

        root /var/www/html/update;
        server_name _;

        location / {
                #limit_rate 500k; # speed is 2000kB/S

                add_header 'Access-Control-Allow-Origin' '*';
                add_header 'Access-Control-Allow-Credentials' 'true';
                add_header 'Access-Control-Allow-Methods' 'GET, POST,OPTIONS,  HEAD, DELETE, PUT';
                add_header 'Access-Control-Allow-Headers' 'Range,Host';
                add_header 'Access-Control-Expose-Headers' 'X-PEAR-ARGS,Content-Length,Content-Range';
                add_header 'X-PEAR-ARGS' $args;
                if ($request_method = 'OPTIONS') {
                        add_header 'Access-Control-Allow-Origin' '*';
                        add_header 'Access-Control-Allow-Credentials' 'true';
                        add_header 'Access-Control-Allow-Methods' 'GET, POST,OPTIONS,  HEAD, DELETE, PUT';
                        add_header 'Access-Control-Allow-Headers' 'Range,Host';
                        return 200;
                }
        }
}

server{
        listen 81;
        listen [::]:81;

        root /var/www/html/update;
        #server_name updatetencent.webrtc.win update.webrtc.win updateoss.webrtc.win;
        server_name _;

        location / {
                #limit_rate 500k; # speed is 2000kB/S

                add_header 'Access-Control-Allow-Origin' '*';
                add_header 'Access-Control-Allow-Credentials' 'true';
                add_header 'Access-Control-Allow-Methods' 'GET, POST,OPTIONS,  HEAD, DELETE, PUT';
                add_header 'Access-Control-Allow-Headers' 'Range,Host';
                add_header 'Access-Control-Expose-Headers' 'X-PEAR-ARGS,Content-Length,Content-Range';
                add_header 'X-PEAR-ARGS' $args;
                if ($request_method = 'OPTIONS') {
                        add_header 'Access-Control-Allow-Origin' '*';
                        add_header 'Access-Control-Allow-Credentials' 'true';
                        add_header 'Access-Control-Allow-Methods' 'GET, POST,OPTIONS,  HEAD, DELETE, PUT';
                        add_header 'Access-Control-Allow-Headers' 'Range,Host';
                        return 200;
                }
        }
}

