user  nginx;
worker_processes auto;

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

events {
  use epoll;
  worker_connections 51200;
  multi_accept on;
}

http {
  include mime.types;
  default_type application/octet-stream;
  server_names_hash_bucket_size 128;
  client_header_buffer_size 32k;
  large_client_header_buffers 4 32k;
  client_max_body_size 1024m;
  client_body_buffer_size 10m;
  sendfile on;
  tcp_nopush on;
  keepalive_timeout 120;
  server_tokens off;
  tcp_nodelay on;

  fastcgi_connect_timeout 300;
  fastcgi_send_timeout 300;
  fastcgi_read_timeout 300;
  fastcgi_buffer_size 64k;
  fastcgi_buffers 4 64k;
  fastcgi_busy_buffers_size 128k;
  fastcgi_temp_file_write_size 128k;
  fastcgi_intercept_errors on;

  #Gzip Compression
  gzip on;
  gzip_buffers 16 8k;
  gzip_comp_level 6;
  gzip_http_version 1.1;
  gzip_min_length 256;
  gzip_proxied any;
  gzip_vary on;
  gzip_types
    text/xml application/xml application/atom+xml application/rss+xml application/xhtml+xml image/svg+xml
    text/javascript application/javascript application/x-javascript
    text/x-json application/json application/x-web-app-manifest+json
    text/css text/plain text/x-component
    font/opentype application/x-font-ttf application/vnd.ms-fontobject
    image/x-icon;
  gzip_disable "MSIE [1-6]\.(?!.*SV1)";

  proxy_ignore_client_abort on;

  server {
    listen 8001; # 监听端口
    # server_name -; # 域名可以有多个，用空格隔开

    #charset koi8-r;

    #access_log  logs/host.access.log  main;
    location / {
      root /opt/web;
      index index.html index.htm; #目录内的默认打开文件,如果没有匹配到index.html,则搜索index.htm,依次类推
    }

    #ssl配置省略
    location /api {
      # rewrite ^.+api/?(.*)$ /$1 break;
      proxy_pass http://ferry_backend:8002; #node api server 即需要代理的IP地址
        proxy_redirect off;
      proxy_set_header Host $host:$server_port;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

    # 登陆
    location /login {
      proxy_pass http://ferry_backend:8002; #node api server 即需要代理的IP地址
      proxy_redirect off;
      proxy_ignore_client_abort on;
      proxy_max_temp_file_size 256m;
      proxy_connect_timeout      90;
      proxy_send_timeout         90;
      proxy_read_timeout         90;
      proxy_buffer_size          4k;
      proxy_buffers              4 32k;
      proxy_busy_buffers_size    32k;
      proxy_temp_file_write_size 64k;
      proxy_http_version 1.1;
      proxy_set_header Connection "";
      proxy_set_header Host $host:$server_port;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

    # 刷新token
    location /refresh_token {
      proxy_pass http://ferry_backend:8002; #node api server 即需要代理的IP地址
        proxy_set_header Host $host:$server_port;
    }

    # 接口地址
    location /swagger {
      proxy_pass http://ferry_backend:8002; #node api server 即需要代理的IP地址
        proxy_set_header Host $host:$server_port;
    }

    # 后端静态文件路径
    location /static/uploadfile {
      proxy_pass http://ferry_backend:8002; #node api server 即需要代理的IP地址
        proxy_set_header Host $host:$server_port;
    }

    #error_page  404              /404.html;    #对错误页面404.html 做了定向配置

    # redirect server error pages to the static page /50x.html
    #将服务器错误页面重定向到静态页面/50x.html
    #
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
      root html;
    }
  }
}