2020年2月26日 星期三

NGINX config

[root@www1 ~]# vi /etc/nginx/nginx.conf
#user  nginx;
user  root;
worker_processes  auto;
worker_rlimit_nofile 100000;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  16382;
    # 告訴nginx收到一個新連接通知後接受儘可能多的連接。
    multi_accept on; 
    accept_mutex off;
    use epoll; 
}


http {
    # 關閉在錯誤頁面中的nginx版本數字
    server_tokens off;
    # 可以讓sendfile()發揮作用。
#    sendfile on;
    # 告訴nginx在一個數據包裡發送所有頭文件,而不一個接一個的發送。
    tcp_nopush on;
    # 告訴nginx不要緩存數據,而是一段一段的發送–當需要及時發送數據時,就應該給應用設置這個屬性,這樣發送一小塊數據信息時就不能立即得到返回值。
    tcp_nodelay on;

    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;


    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for" $request_time $upstream_response_time "$http_accept_encoding" "$upstream_cache_status"' ;

     log_format rt_cache '$remote_addr - $upstream_cache_status [$time_local]  '
                      '"$request" $status $body_bytes_sent '
                      '"$http_referer" "$http_user_agent"';

    access_log  /var/log/nginx/access.log  main;
    access_log  /var/log/nginx/cache.log   rt_cache;

    sendfile        on;
#    tcp_nopush     on;
#    tcp_nodelay    on;


    keepalive_timeout 0;
#    keepalive_timeout  300;
    keepalive_requests 200000;
    #keepalive_timeout  65;
    #iproxy_read_timeout 300;
    #fastcgi_read_timeout 300;

    open_file_cache max=10240 inactive=20s;
    open_file_cache_valid 30s;
    open_file_cache_min_uses 1;

    #client_body_timeout 60s;
    #gzip                off;
    gzip                on;
    gzip_buffers        4 16k;
    gzip_http_version   1.0;
    gzip_types          text/plain  application/x-javascript text/css application/xml application/json text/javascript application/javascript;
    #gzip_types          text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
    gzip_static on;


    gzip_disable "msie6";

    gzip_vary on;
    gzip_proxied any;
    gzip_comp_level 6;
    gzip_min_length 1536;
#    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript application/vnd.ms-fontobject application/x-font-ttf font/opentype image/svg+xml image/x-icon;


    proxy_cache_path /data/nginx/cache levels=1:2 keys_zone=my_cache:10m max_size=2g inactive=60m use_temp_path=off;
    # Set cache key to include identifying components
    #proxy_cache_key $scheme$proxy_host$request_uri;
    #proxy_cache_key $scheme$host$request_uri$is_args$args;
    proxy_cache_key $host$request_uri$is_args$query_string;
    include /etc/nginx/conf.d/*.conf;
}
[root@www1 ~]# cat /etc/nginx/conf.d/default.conf
upstream ncdrapi {
  server 10.123.123.17:8009 max_fails=2 fail_timeout=10s;
}

upstream auth_api {
  server 10.123.123.17:8008 max_fails=2 fail_timeout=10s;
}


server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;
    #listen 443 ssl http2 default_server;
    #listen [::]:443 ssl http2 default_server;

    listen 443 ssl http2;
    listen [::]:443 ssl http2;

    ssl_certificate     /etc/nginx/conf.d/front-end.strangled.net/server.crt;
    ssl_certificate_key /etc/nginx/conf.d/front-end.strangled.net/private.key;
    ssl_dhparam /etc/nginx/conf.d/front-end.strangled.net/dhparams.pem;



    ssl_buffer_size 4k;
    ssl_session_cache shared:SSL:9m;
    ssl_session_cache shared:ssl_session_cache:10m;
    ssl_session_timeout 5m;
#    ssl_protocols TLSv1.3;
    ssl_protocols TLSv1.2 TLSv1.3;
    #ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
    #remove TLS_RSA_WITH_3DES_EDE_CBC_SHA
    ssl_ciphers         HIGH:!aNULL:!MD5;
#    ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA';
    ssl_stapling on;
    ssl_stapling_verify on;
#       ssl_trusted_certificate /path/to/full_chain.pem;
        ssl_trusted_certificate /etc/nginx/conf.d/front-end.strangled.net/server.crt;
        resolver 210.69.1.1 210.69.2.1 valid=300s;
        resolver_timeout 5s;

    add_header X-Frame-Options "DENY";
    add_header X-Content-Type-Options nosniff;
    add_header X-XSS-Protection "1; mode=block";
    add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; preload";
#    resolver 8.8.8.8 8.8.4.4 valid=300s;
#    resolver_timeout 5s;
    location ~ /\.ht {
    deny all;
    }

        add_header X-Cache-Status $upstream_cache_status;
    location /rmrescad/ {
       proxy_pass http://ncdrapi/rmrescad/;
       # 定義 header 變數, 記錄使用者的 IP
       proxy_set_header X-Real-IP $remote_addr;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
       proxy_max_temp_file_size 0;
    }

    location /caseinfo/ {
       proxy_pass http://ncdrapi/caseinfo/;
       # 定義 header 變數, 記錄使用者的 IP
       proxy_set_header X-Real-IP $remote_addr;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
       proxy_max_temp_file_size 0;
    }

    location /rmresfca/ {
       proxy_ignore_headers "Set-Cookie";
       proxy_hide_header "Set-Cookie";
       proxy_cache my_cache;
       proxy_cache_valid 200 304 1s;

       proxy_cache_methods GET POST;  #增加此行
       proxy_ignore_headers X-Accel-Expires Expires Cache-Control;
       proxy_redirect off;
       proxy_cache_revalidate on;
       proxy_cache_min_uses 1;
       proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
       proxy_cache_lock on;


       proxy_pass http://ncdrapi/rmresfca/;
       # 定義 header 變數, 記錄使用者的 IP
       proxy_set_header X-Real-IP $remote_addr;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
       proxy_max_temp_file_size 0;
    }

    location /rmressca/ {
       proxy_pass http://ncdrapi/rmressca/;
       # 定義 header 變數, 記錄使用者的 IP
       proxy_set_header X-Real-IP $remote_addr;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
       proxy_max_temp_file_size 0;
    }

    location /rmrestca/ {
       proxy_pass http://ncdrapi/rmrestca/;
       # 定義 header 變數, 記錄使用者的 IP
       proxy_set_header X-Real-IP $remote_addr;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
       proxy_max_temp_file_size 0;
    }

    location /rmresdef/ {
       proxy_pass http://ncdrapi/rmresdef/;

       # 定義 header 變數, 記錄使用者的 IP
       proxy_set_header X-Real-IP $remote_addr;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
       proxy_max_temp_file_size 0;
    }


    location /rmreq/ {
       proxy_ignore_headers "Set-Cookie";
       proxy_hide_header "Set-Cookie";

       proxy_pass http://ncdrapi/rmreq/;

       # 定義 header 變數, 記錄使用者的 IP
       proxy_set_header X-Real-IP $remote_addr;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
       proxy_max_temp_file_size 0;

    }

         # 快取 集散地
    location /stockstation/ {
       proxy_pass http://ncdrapi/stockstation/;

       # 定義 header 變數, 記錄使用者的 IP
       proxy_set_header X-Real-IP $remote_addr;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
       proxy_max_temp_file_size 0;
    }


    # 快取 rmdisa/querycaseda/ 物資類別
    location /rmdisa/ {
       proxy_pass http://ncdrapi/rmdisa/;

       # 定義 header 變數, 記錄使用者的 IP
       proxy_set_header X-Real-IP $remote_addr;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
       proxy_max_temp_file_size 0;
    }

    #RM250: 入庫作業
    location /rmstation/ {
       proxy_pass http://ncdrapi/rmstation/;

       # 定義 header 變數, 記錄使用者的 IP
       proxy_set_header X-Real-IP $remote_addr;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
       proxy_max_temp_file_size 0;
    }

    #RM250: 入庫作業
    location /rmsdetail/ {
       proxy_pass http://ncdrapi/rmsdetail/;

       # 定義 header 變數, 記錄使用者的 IP
       proxy_set_header X-Real-IP $remote_addr;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
       proxy_max_temp_file_size 0;
    }

    location /unmarshal/ {
       proxy_pass http://ncdrapi/unmarshal/;

       # 定義 header 變數, 記錄使用者的 IP
       proxy_set_header X-Real-IP $remote_addr;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
       proxy_max_temp_file_size 0;
    }

    location /marshal/ {
       proxy_pass http://ncdrapi/marshal/;

       # 定義 header 變數, 記錄使用者的 IP
       proxy_set_header X-Real-IP $remote_addr;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
       proxy_max_temp_file_size 0;
    }



        # 首頁物資查詢
    location /homepage/ {
       proxy_pass http://ncdrapi/homepage/;

       # 定義 header 變數, 記錄使用者的 IP
       proxy_set_header X-Real-IP $remote_addr;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
       proxy_max_temp_file_size 0;
    }

        # 物資圖示 快取 1小時
    location /materialImg/ {
       proxy_ignore_headers "Set-Cookie";
       proxy_hide_header "Set-Cookie";
       proxy_cache my_cache;
       proxy_cache_valid 200 304 1h;
       proxy_cache_methods GET POST;  #增加此行
       proxy_ignore_headers X-Accel-Expires Expires Cache-Control;
           proxy_redirect off;
       proxy_cache_revalidate on;
       proxy_cache_min_uses 1;
       proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
       proxy_cache_lock on;

       proxy_pass http://ncdrapi/materialImg/;

       # 定義 header 變數, 記錄使用者的 IP
       proxy_set_header X-Real-IP $remote_addr;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
       proxy_max_temp_file_size 0;
    }

    location /frontend/ {
       proxy_pass http://ncdrapi/frontend/;

       # 定義 header 變數, 記錄使用者的 IP
       proxy_set_header X-Real-IP $remote_addr;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
       proxy_max_temp_file_size 0;
    }

    location /api/ {

       proxy_pass http://10.123.123.17:8008/api/;
       # 定義 header 變數, 記錄使用者的 IP
       proxy_set_header X-Real-IP $remote_addr;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
       proxy_max_temp_file_size 0;
    }

    location /oauth/ {

       proxy_pass http://10.123.123.17:8008/oauth/;
       # 定義 header 變數, 記錄使用者的 IP
       proxy_set_header X-Real-IP $remote_addr;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
       proxy_max_temp_file_size 0;
    }

    #EMIC 查詢最新災害應變專案
    location /emicOpenCases/ {
        proxy_ignore_headers "Set-Cookie";
        proxy_hide_header "Set-Cookie";
        proxy_cache my_cache;
        proxy_cache_valid 200 304 1s;

        proxy_cache_methods GET POST;  #增加此行
        proxy_ignore_headers X-Accel-Expires Expires Cache-Control;
            proxy_redirect off;
        proxy_cache_revalidate on;
        proxy_cache_min_uses 1;
        proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
        proxy_cache_lock on;

       proxy_pass http://10.123.123.10:80/emicOpenCases/;

       # 定義 header 變數, 記錄使用者的 IP
       proxy_set_header X-Real-IP $remote_addr;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
       proxy_max_temp_file_size 0;
    }

    location  /nginx {
       proxy_cache off;
       proxy_pass http://localhost:2080/nginx;
    }

   # 線上 http://223.200.166.225/EDXL/
    location /EDXL/ {
       proxy_pass https://10.123.123.9/EDXL/;
       # 定義 header 變數, 記錄使用者的 IP
       proxy_set_header X-Real-IP $remote_addr;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
       proxy_max_temp_file_size 0;
    }

    # 測試 http://223.200.166.225/EDXL_test_material/
    location /EDXL_test_material/ {
       proxy_pass https://10.123.123.9/EDXL_test_material/;
       # 定義 header 變數, 記錄使用者的 IP
       proxy_set_header X-Real-IP $remote_addr;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
       proxy_max_temp_file_size 0;
    }

    location / {
       root /home/uiux/admin;
       #root   /usr/share/nginx/html;
       index  index.html;
    }

    location = /nginx_status {
      stub_status on;
      access_log off;
      #allow 223.200.181.30;
      allow 127.0.0.1;
      #allow 10.123.123.13;
      deny all;
      #allow all;
    }

    location /.well-known/acme-challenge/ {
      alias /var/www/dehydrated/;
    }   
}

沒有留言:

張貼留言