Cross-domain say popular point is to use Ajax in a network to get the specific content of B site, this is the cross-domain. There are two forms of cross-domain, one is a cross-domain of different ports of the same IP, and one is a cross-domain of different IPs.
Now talk about the project used to solve the cross-domain file upload method, the middle encountered a variety of pits do not say; The upload method is applicable to both of these scenarios.
Note that the schema is using Nginx as the Web server.
Front-end HTML
<form id= "fp" action= "method=" post "enctype=" Multipart/form-data ">
<table >
<tr >
<td width= "align=" "left" ><input type= "file" name= "file" id= "file"/></td>
<TD width= "align=" "left " ><input id= "sub" style= "Background-color: #669900;" onclick= "Ajaxup () "Type=" button "name=" Submit "value=" Upload "/>
</tr>
</table>
</form>
Ajax
Function Ajaxup () {
var formelement = Document.forms.namedItem ("FP");
var xhr = new XMLHttpRequest ();
Xhr.open ("POST", uphttp, true);
Xhr.send (New FormData (formelement));
Xhr.onload = function (e) {
var messg = eval (' (' + this.response + ') ');
Cookies (messg.id);
Location.reload ();
}
}
Nginx configuration #user www www; Worker_processes 1;
#启动进程, usually set to equal to the number of CPUs Worker_rlimit_nofile 204800; events {use Epoll; #epoll是多路复用IO (I/O multiplexing) in one way, but only for linux2.6 above the core, can greatly improve the performance of Nginx Worker_connections 100; Maximum number of concurrent links #单个后台worker process processes} HTTP {Access_log/opt/v0.1/wordfreserver/ngx_openresty/logs/access_appname.log
Combined
Error_log/opt/v0.1/wordfreserver/ngx_openresty/logs/error_appname.log Crit; Include Mime.types;
#设定mime类型, the type is defined by the Mime.type file Default_type application/octet-stream; #sendfile instruction Specifies whether Nginx calls the Sendfile function (zero copy mode) to output files, for general applications, #必须设为 on, if used for downloading applications such as disk IO heavy-duty applications, can be set to off to balance disk and network I/O processing speed
Reduce the uptime of the system.
Sendfile on;
Tcp_nopush on;
Tcp_nodelay on; Keepalive_timeout 60; #连接超时时间 client_header_buffer_size 2k;
#设定请求缓冲 lua_shared_dict config 1m;
#init_by_lua_file ' Server/init.lua ';
server{Listen 8000; server_name LocalhosT
Location ~*/(\w+)/static/{root/opt/v0.1/wordfreserver/ngx_openresty/web2py/applications/;
} location/{Uwsgi_pass 127.0.0.1:9001;
Include Uwsgi_params;
}} server {listen 7777; #侦听端口 server_name localhost; Lua_code_cache on;
#上线后请设置为on client_max_body_size 512m;
Location/favicon.ico {log_not_found off; access_log off;}
Location/wordfreq/upfile {if ($request _method = ' POST ') {add_header ' access-control-allow-origin ' * ';
#set $debug "on";
Content_by_lua_file Server/upfile.lua; }} location/wordfreq/act {add_header ' access-control-allow-origin ' * '; set $debug "on"; Content_by_lua_file ser Ver/act.lua;
} location/test {Default_type text/html; Content_by_lua ' Ngx.say ("Hello World") ';}
Location ~* ^ (. +\.txt) $ {add_header ' access-control-allow-origin ' * '; Root/opt/v0.1/Wordfreserver/result;
Access_log off;
Expires 30d; Add_header content-disposition "attachment;
Filename=$1 ";
}
}
Add Add_header ' access-control-allow-origin ' * to a request service on the server side ; will be able to achieve the leap and be able to get response, and there will be no warning message.