52AV璈A|52AV.ONE

 曉撖蝣
 蝡唾酉
敹急瑕
  • av隢憯BBS
  • 璈A
  • 芣瑟憭瘚
  • 鞎澆
  • 52av鋆貉摰
  • 銝剜-銝剖銝餅
Yahoo!憟拇撠
望: 璈A
Google憟拇撠
望: 璈A
     
亦: 12683|敺: 0
銝銝銝駁 銝銝銝駁

[nginx|php-fpm] Nginx銋CORS嚗Cross-Origin Resource Sharing嚗頝其皞鞈皞曹澈嚗靘撖衣暸脫迫憭慦擃鞈皞

[銴鋆賡包
頝唾唳摰璅撅
璅銝
潸” 2019-2-20 09:34:17 | 芰閰脖 撣 |摨閬 |梯璅∪
隞乩gist.github.comreverse proxied APIs蝭靘:
' G/ e! w% T) D! O1 w) q# P
! I" d6 T# [8 C$ q

4 `7 J6 B+ v9 g4 x, T
# CORS header support
1 _% ~5 \3 V% g" g7 B#
3 i; X# ~+ V6 w9 ?7 U# One way to use this is by placing it into a file called "cors_support"% L% a# N1 V  y) O. H9 e
# under your Nginx configuration directory and placing the following
7 P! m6 F3 |, Q! u! s% P3 @# statement inside your **location** block(s):
8 Y& s# o( j- \* {' a! E#2 C2 u" X9 ^) n/ S0 W1 J
#   include cors_support;
8 {% v) Y' @9 Y: Q1 {#& g& q+ a8 ?9 c
# As of Nginx 1.7.5, add_header supports an "always" parameter which8 Q2 |" o1 Q! E- e! f1 v( h
# allows CORS to work if the backend returns 4xx or 5xx status code.
% M; d8 @  [, c3 f3 i#
$ q  F; s# o5 y- k2 j5 k7 `# For more information on CORS, please see: http://enable-cors.org/. `" F  b) d- a* j; Y, u9 P
# Forked from this Gist: https://gist.github.com/michiel/1064640
1 t# c7 I# V) c" a#
+ i) O: j& g! x5 |; K, h9 n1 N8 R) G  P" A, m7 [- _2 T0 D
set $cors '';# A- y. y# [4 m. J- v" b9 T+ B
if ($http_origin ~ '^https?://(localhost|www\.yourdomain\.com|www\.yourotherdomain\.com)$') {
3 E' d- S0 {+ t: Q4 {+ m        set $cors 'true';! ?1 T. n7 W9 y: y
}# m! G8 G" Y7 a% R" F

5 m5 ^' {, o; ]- n7 H% ^# z! Z& kif ($cors = 'true') {/ |! c: U, _; X. [- T
        add_header 'Access-Control-Allow-Origin' "$http_origin" always;
" `8 n  l/ P# O5 J  p        add_header 'Access-Control-Allow-Credentials' 'true' always;
' C' Q% r# C# t1 M0 {        add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
9 z: q) Y: v- X1 q( _        add_header 'Access-Control-Allow-Headers' 'Accept,Authorization,Cache-Control,Content-Type,DNT,If-Modified-Since,Keep-Alive,Origin,User-Agent,X-Requested-With' always;1 R5 |% @4 r9 c/ V! U6 A8 Y5 x
        # required to be able to read Authorization header in frontend8 Z6 g  v8 h+ n: ?- w- g$ w
        #add_header 'Access-Control-Expose-Headers' 'Authorization' always;1 E: \8 F* J) q- M
}
+ D0 @) Q) b0 ?% d
* x+ W) |0 m) N2 Vif ($request_method = 'OPTIONS') {4 K* ~- A9 H) b4 ^2 b: I$ t6 I) T* L
        # Tell client that this pre-flight info is valid for 20 days9 l' Z( @) g% K7 S3 F
        add_header 'Access-Control-Max-Age' 1728000;
9 x; j/ ~* g4 D# a3 l8 ]        add_header 'Content-Type' 'text/plain charset=UTF-8';% F' D7 B& ^# g9 B' l0 s! s* @
        add_header 'Content-Length' 0;
2 |0 F% A2 m  k( ]) y7 a# I% M        return 204;2 A+ ^+ b$ z. {1 q$ c; B* ~
}
https://gist.github.com/Stanback/7145487#file-nginx-conf 閮隢蝭靘:

( b7 B1 H8 N4 Z6 f
if ( $request_method !~ ^(GET|POST|HEAD|OPTIONS|PUT|PATCH|DELETE)$ ) {     return 444;
+ i( C  @3 a/ l/ c* T6 m. v}6 }4 a# I4 k* y1 ]# M& o
set $origin $http_origin;
- f$ _+ u8 ?8 I/ q7 C- ], Kif ($origin !~ '^https?://(subdom1|subdom2)\.yourdom\.zone$') {  Z, Q3 w. a3 E4 D% w$ }0 L" h! E. \
     set $origin 'https://default.yourdom.zone';
5 O3 M( I( ~, A9 A$ S}, R, H, C/ P, @6 h) T5 C. g) d
if ($request_method = 'OPTIONS') {9 o5 @8 |: }; p/ O8 o+ _
     add_header 'Access-Control-Allow-Origin' "$origin" always;
" u/ @- H/ [" x6 T! C) n     add_header 'Access-Control-Allow-Methods' 'GET, POST, PATCH, PUT, DELETE, OPTIONS' always;9 W! w' ?8 _2 W& m- F; a- n# _$ c
     add_header 'Access-Control-Allow-Headers' 'Content-Type, Accept, Authorization' always;9 b- [7 Y% p/ G2 W+ Q7 C
     add_header 'Access-Control-Allow-Credentials' 'true' always;
4 V, s# z& _* @9 @9 B     add_header Access-Control-Max-Age 1728000;   #20 days   
' r" s$ L- a, X3 d, u6 b: F3 @2 L     add_header Content-Type 'text/plain charset=UTF-8';
  `; s8 T' b+ A) A& L3 z$ Q: a" S     add_header Content-Length 0;% |' b% c& g3 l. K8 z  I- H
     return 204;! w# f. v( G# a1 h6 A* y0 |! s
}3 m& }# q. G4 Y) @4 e
if ($request_method ~ '(GET|POST|PATCH|PUT|DELETE)') {. C! I  n# U% ?2 Q9 r* [" Q1 K
     add_header Access-Control-Allow-Origin "$origin" always;* ~3 Y- c3 v$ [# N! S# [
     add_header Access-Control-Allow-Methods 'GET, POST, PATCH, PUT, DELETE, OPTIONS' always;  S$ ]: `, M* [
     add_header Access-Control-Allow-Headers 'Content-Type, Accept, Authorization' always;8 b7 |0 o0 b2 H( J* A7 S- L3 @
     add_header Access-Control-Allow-Credentials true always;
, Z  R2 F+ b5 ?& S9 C4 c}
Access-Control-Allow-Origin Multiple Origin Domains? 靘摮:
# based on https://gist.github.com/4165271/. D0 q2 L! w: F4 b+ R: s' X- H
#
0 f/ W1 u# F: R  |# p  A% Q# Slightly tighter CORS config for nginx4 S1 `& r" J% G% |0 F
#* I! a& b1 f. n& w5 ?) D& v
# A modification of https://gist.github.com/1064640/ to include a white-list of URLs5 Z; W* k& G8 U6 W' r+ t: j
#$ Z! K, ?- I- p8 g8 P$ a
# Despite the W3C guidance suggesting that a list of origins can be passed as part of' h& r2 x7 n  o
# Access-Control-Allow-Origin headers, several browsers (well, at least Firefox)$ e4 l3 ~6 q9 ^2 E: N$ M
# don't seem to play nicely with this.
: Q3 c$ t8 B' [4 G#
5 U  ]/ d2 l$ X  {5 `- k' Q2 Z# To avoid the use of 'Access-Control-Allow-Origin: *', use a simple-ish whitelisting
. w" X0 N& P; s7 \; [: G5 i# method to control access instead.
& i& |! r8 C1 _: s#
- {5 N) r: z6 L# NB: This relies on the use of the 'Origin' HTTP Header.
2 K4 o3 p, v& }4 z' {$ k9 N- k8 \; }! I; _# }0 {" {
location / {
3 U' H* [7 Q3 m1 D3 \' a
# d+ h7 \& y: r4 o    if ($http_origin ~* (^https?://([^/]+\.)*(domainone|domaintwo)\.com$)) {1 z7 {5 j6 j% @$ U2 o
        set $cors "true";
# K: Z# o5 L/ X" w    }+ u3 s3 V8 b, J3 u

# |6 Y' Q9 Y1 g0 D; _, b& n    # Nginx doesn't support nested If statements. This is where things get slightly nasty.
: B. s" V( W& ?: _( [    # Determine the HTTP request method used
0 V' N% ]* f1 E! y2 l) ^. w4 n/ _    if ($request_method = 'OPTIONS') {6 f# j3 T  C* }* c2 w! A' P
        set $cors "${cors}options";3 I& S3 h( B1 T. T8 ~& l" N* Y4 e# x
    }! p6 w! S& [! E
    if ($request_method = 'GET') {  W0 s$ ^: }  F/ O8 s
        set $cors "${cors}get";
1 k$ G9 O. E$ `1 W  H% J    }
2 M4 E% i- |$ S, Y0 o( S    if ($request_method = 'POST') {1 @1 \9 N: _; a0 U1 j' W% E6 Q" i
        set $cors "${cors}post";1 _2 w5 d& Y# i1 P, S7 V
    }
# {  F& _, Z5 x. `  o; t# k6 j$ Q& H9 [$ t: H
    if ($cors = "true") {
. K4 Q6 M& m6 i& P. _  M& ~        # Catch all incase there's a request method we're not dealing with properly( i9 T# a6 B" a4 r  S/ D9 L8 r* Y
        add_header 'Access-Control-Allow-Origin' "$http_origin";
# [  `: a0 r& Z    }
( d! b# j- p  j1 C" O' ]" y* Y! j( p) R" D, c) C
    if ($cors = "trueget") {, b: m3 b& M7 ^
        add_header 'Access-Control-Allow-Origin' "$http_origin";
; |( n  F9 h  C6 N        add_header 'Access-Control-Allow-Credentials' 'true';
) A1 _  |$ ]" W  G8 e        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';5 y1 @0 T$ j# w7 Z
        add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
  x7 a/ P7 j7 \8 j7 [; R- A( v- _  U6 g    }* T0 b% I, ^; K8 Q
, q1 x' w5 d- N9 c4 U
    if ($cors = "trueoptions") {2 h7 R2 g( {# y& s* E: o% L
        add_header 'Access-Control-Allow-Origin' "$http_origin";! C8 H4 |( k$ K$ X' F) t

+ K3 i- O; p5 ~( i: c5 c% O" Q) F        #* S2 e# j, j2 O9 j/ f( |& f+ t
        # Om nom nom cookies! N$ n/ ^& g& O, {6 G: J# I
        #' g( T8 D& s' g
        add_header 'Access-Control-Allow-Credentials' 'true';
; T+ u; ^' P5 Q! t' {2 P. ?        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
  |" V7 r) I! Y" W9 K" s2 M) K0 A, p2 B5 e2 M* {: T) \! L7 p
        #
3 |  h8 Q: T( J" ^; G3 a9 ?        # Custom headers and headers various browsers *should* be OK with but aren't7 I! v* P; I6 i! w6 E7 m# t- f! F* Z
        #
+ s- ?' ^6 D) R/ _6 y4 x$ o        add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
. z5 ^! F* }  p4 e' Y% M( U! b# ~; P
        #
2 }$ ~' @: @' n; n        # Tell client that this pre-flight info is valid for 20 days/ E# u! O. t7 i
        #
4 k3 d7 t' p' o7 y        add_header 'Access-Control-Max-Age' 1728000;% c0 a! C9 s  ?
        add_header 'Content-Type' 'text/plain charset=UTF-8';
7 c3 _( t" _7 _, R# B        add_header 'Content-Length' 0;9 v3 V/ H) w3 k5 D
        return 204;  [. `9 t- ?1 s  b  {* p- ]# i
    }- `. k8 Q& @/ d: x6 M5 w

" ?9 b. D1 \# w) L1 I    if ($cors = "truepost") {2 B. J0 {8 [' t- U$ X! O
        add_header 'Access-Control-Allow-Origin' "$http_origin";
, I# p9 d* ^4 m: a        add_header 'Access-Control-Allow-Credentials' 'true';1 S) R/ ]5 e* g/ P1 i7 v$ @
        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
, Y& z+ S+ o, r9 U        add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
" |  C* V& R- n( S2 G- Q, b/ M    }
' u# U9 s% Z+ w  t) G& j7 b. T' _- S- K
}
5 I9 i% M' @0 |# u* u6 N

. D" m4 V; u% ]

雿輻券

祉蝛閬

BT蝳

砍憛批捆靘餉衣雯頝臬批捆蝝颲行粹嗥蝬脩嚗摰撟湔遛嚗嚗甇脖誑銝嗅啣摰嗆摰撟湧翩鈭箏ㄚ孵舫脣伐銝憿亙祉璇甈橘芣遛18甇 雓蝯脣亦閬賬粹脩芣遛18甇脖芣撟渡雯閬賜雯頝臭嗥批捆鞈閮嚗撱箄降典舫脰蝬脰楝批捆蝝蝯蝜ICRA蝝摰鋆閮剖 (粹蝯行霅 祉蝬脣銝蝝瘛函隢憯啣嚗祉閮剜蝞∠)

QQ|撠暺撅||52AV璈A

GMT+8, 2024-12-22 12:16 , Processed in 0.067695 second(s), 15 queries .

蝯∠.撱

52avtv@gmail.com | QQ:2405733034     since 2015-01

鋆貉憒 敹恍敺 餈銵