nginx解決golang介面跨域問題

2021-09-24 00:08:52 字數 1052 閱讀 1286

user  nginx nginx;

worker_processes 8;

worker_rlimit_nofile 102400; #配置nginx開啟最大檔案數 (每個工作程序繫結乙個cpu,worker_cpu_affinity配置)

worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000;

#error_log logs/error.log;

#error_log logs/error.log notice;

error_log logs/error.log info;

pid logs/nginx.pid;

events

http

proxy.conf 配置檔案

if ($request_method = 'options') 

add_header 'access-control-allow-origin' '*';

add_header 'access-control-allow-credentials' 'true';

add_header 'access-control-allow-headers' 'authorization,content-type,accept,origin,user-agent,dnt,cache-control,x-mx-reqtoken,x-requested-with,x-custom-header';

add_header 'access-control-allow-methods' 'get,post,options';

server.conf配置檔案

server

}

用nginx解決golang的介面跨域問題

在有跨域的反向**include proxy.conf即可

golang介面解決跨域問題

通過設定響應頭,允許跨域請求的方式來解決。首先編寫設定響應頭的中介軟體 然後使用此中介軟體,應確保這個中介軟體在其他中介軟體之前被使用到,這樣所有的響應都會成功設定。此處以gin框架為例。grouter gin.new grouter.use cors.cors cors.options grout...

關於golang面向介面

傳統語言的繼承多型由go語言的介面完成 所以go語言的介面比較靈活 go語言介面由使用者定義 傳統語言由實現者定義 先來乙個簡單的介面示例 package mock 介面方法專用包 type retriever struct func r retriever get url string strin...

golang 基礎 介面定義

demo4.go package main import fmt type student struct func this student init name string,age int,int func main s.init 張高元 20,1 fmt.println s 我們列印發現init...