解決同源策略問題(伺服器端)

2021-10-10 15:37:24 字數 1494 閱讀 5083

目錄

問題描述:

伺服器端解決方案

- apache2

- nginx

front.local.com 為前端**(a站), img.local.com 為站(b站),當a站中的js訪問到b站資源時,報錯誤:"the image has been blocked by cors policy",即瀏覽器的同源策略限制了訪問。

首先, 確定apahe2.conf 有mod_headers支援

loadmodule headers_module /usr/lib/apache2/modules/mod_headers.so
其次,

serveradmin admin@php5 

servername img.local.com

serveralias *.img.local.com

documentroot ""

header set access-control-allow-origin *

header set access-control-allow-methods "post, get, options, delete, put"

header set access-control-allow-credentials true

header set access-control-allow-headers "origin, x-requested-with, content-type, accept, authorization"

# use mod_rewrite for pretty url support

rewriteengine on

# if a directory or a file exists, use the request directly

rewritecond % !-f

rewritecond % !-d

# otherwise forward the request to index.php

rewriterule . index.php

options indexes followsymlinks multiviews

allowoverride all

order allow,deny

allow from all

方法二:全域性起效,修改apache2.conf

header set access-control-allow-origin: "*"

header set access-control-allow-methods: "get,post,put,delete,options"

header set access-control-allow-headers: "content-type"

server 

}

socket伺服器端

伺服器 include winsock2.h include string.h include stdio.h include time.h include stdarg.h include stdlib.h pragma comment lib,ws2 32 void errexit const ...

kerberos伺服器端

1.安裝tcl wget tar zvxf tcl8.5.12 src.tar.gz cd tcl8.5.12 cd unix configure make make install 3.解壓 tar xvf krb5 1.10.3 signed.tar tar zvxf krb5 1.10.3.t...

C tcp伺服器端

伺服器端 include stdafx.h include winsock2.h pragma comment lib,ws2 32.lib include using namespace std int tmain int argc,char ar 建立套接字 sserver socket af ...