我积极解决 发表于 2017-12-23 14:31:46

Kubernetes

1 upstream web {  

2   server my-server-1:3005 max_fails=1 fail_timeout=10s;  

3   server my-server-2:3005 max_fails=1 fail_timeout=10s;  

4 }  

5  
6 upstream api {
  

7   server my-server-1:3006 max_fails=1 fail_timeout=10s;  

8   server my-server-2:3006 max_fails=1 fail_timeout=10s;  

9 }  

10  
11 server {
  
12   listen 80;
  
13   listen       443 ssl;
  
14   
  
15   ssl_certificate    /etc/nginx/conf.d/cert/wildcard.mysite.pem;
  
16   ssl_certificate_key    /etc/nginx/conf.d/cert/wildcard.mysite.key;
  
17   location / {
  
18      proxy_pass http://web;
  
19   proxy_set_header X-Forwarded-Host $host;
  
20   proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  
21   }
  
22
  
23   location ~^/(api) {
  
24   proxy_pass http://api;
  
25   proxy_set_header X-Forwarded-Host $host;
  
26   proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  
27
  
28   if ($http_origin ~* (^(https?://(?:.+\.)?mysite\.com)$)) {
  
29       set $cors "CORS";
  
30       set $cors_method "${cors}_${request_method}";
  
31   }
  
32
  
33   if ($cors_method = "CORS_OPTIONS") {
  
34       add_header 'Access-Control-Allow-Origin' '$http_origin';
  
35       add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS';
  
36       #
  
37       # Custom headers and headers various browsers *should* be OK with but aren't
  
38       #
  
39       add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
  
40       #
  
41       # Tell client that this pre-flight info is valid for 20 days
  
42       #
  
43       add_header 'Access-Control-Max-Age' 1728000;
  
44       add_header 'Content-Type' 'text/plain ';
  
45       add_header 'Content-Length' 0;
  
46       return 204;
  
47   }
  
48
  
49   if ($cors = "CORS") {
  
50       add_header 'Access-Control-Allow-Origin' '$http_origin';
  
51       add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS';
  
52       add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
  
53   }
  
54   }
  
55 }
页: [1]
查看完整版本: Kubernetes