1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
server {
    listen 80;
    server_name www.dianduidian.com;
    rewrite ^(.*) https://www.dianduidian.com$1 permanent;
}

server {
    listen 443 ssl http2;
    server_name www.dianduidian.com;

    access_log /var/log/nginx/access-www.dianduidian.com.log;
    error_log /var/log/nginx/error-www.dianduidian.com.log;

    ssl_certificate  /etc/nginx/ssl/_.dianduidian.com.pem;
    ssl_certificate_key  /etc/nginx/ssl/_.dianduidian.com.key;

    #openssl dhparam -dsaparam -out /etc/nginx/ssl/dhparam.pem 4096
    ssl_dhparam /etc/ssl/certs/nginx/dhparam.pem;

    ssl_session_cache shared:SSL:10m;  # 1m holds approx 4000 sessions
    ssl_session_timeout 1d;
    ssl_session_tickets off;
    ssl_protocols TLSv1.2 TLSv1.3; # nginx 1.13+
    ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
    ssl_prefer_server_ciphers on;
    add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; preload";

    proxy_max_temp_file_size   0;
    proxy_connect_timeout      60;
    proxy_send_timeout         60;
    proxy_read_timeout         120;
    proxy_buffer_size          16k;
    proxy_buffers              4 32k;
    proxy_busy_buffers_size    64k;
    proxy_temp_file_write_size 64k;
    proxy_intercept_errors     off;

    client_body_buffer_size    10m;
    client_max_body_size       10m;

    location ~ swagger-ui.html {
        return 403;
    }

    location / {
        if ($request_method = 'OPTIONS') {
            add_header 'Access-Control-Allow-Origin' $http_origin;
            add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS,DELETE,PUT';
            add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization,Token';
            add_header 'Access-Control-Max-Age' 1728000;
            add_header 'Access-Control-Allow-Credentials' 'true';
            add_header 'Content-Type' 'text/plain; charset=utf-8';
            add_header 'Content-Length' 0;
            return 204;
        }
        if ($http_origin ~ (.+)?\.dianduidian\.com$){
            add_header 'Access-Control-Allow-Origin' $http_origin always;
            add_header Access-Control-Request-Method 'GET, POST, OPTIONS, DELETE, PUT' always;
            add_header 'Access-Control-Allow-Credentials' 'true' always;
            add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization,Token' always;
        }

        proxy_pass http://k8s.ingress.svc;
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
    }
}

参考:

https://gist.github.com/denji/8359866