Skip to content

Nginx配置

概述

这里主要使用了Nginx的反向代理功能,实现主要是基于配置文件。云平台内所在路径/etc/nginx/conf.d,默认文件名default.conf

对于一般的项目我们提供一个通用的配置文件

bash
server{
    listen 8080;
    server_name localhost;
location / {
    root /tmp/static;
    index index.html index.htm;
}
location /api {
    proxy_set_header Host $host;
    proxy_pass http://hcce-test:8087;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
    root /usr/share/nginx/html;
}
}

盘古Nginx常用配置

针对Pangea,我们提供了一份常用的Nginx配置文件组,以更好地支撑系统的运行。

  1. 搭载位置/etc/nginx/conf.d/default.conf

    bash
    server {
    listen       8080;
      server_name  localhost;
    
      #默认主页
      index  index.html;
    
    	#静态页面目录
      root /tmp/static;
    
      client_max_body_size 200m;
    
        proxy_connect_timeout 75s;
        proxy_send_timeout 60s;
        proxy_read_timeout 60s;
    
        location / {
            try_files $uri $uri/ /index.html; #主要是这句配置
            #add_header Access-Control-Allow-Origin *;
            #add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
            #add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
               
        }
        location ~* \.(gif|jpg|jpeg|png|css|js) {
                expires 1h;
        }
    
        # 用于页面模板的图片显示。注意:本条配置项要保证放到/minio配置项(如果有的话)的前面
        location /minio/templateCenter/ {
            proxy_pass http://10.19.44.209:8060/pangea-prd-bucket/templateCenter/;
        }
    
        # kkfile
    	    location /pangeakkfile/ {
    	        proxy_pass http://kkfile-pangea-2-test-oracle.devapps.hisense.com/;
    	    }
    
        # 开发平台微应用
        location /pangeadevplatform/ {
            proxy_pass http://pangea-devplatform-web.prdapp.hisense.com/;
        }
    
        # 报表
        location /ureport/ {
            proxy_pass http://pangea-ureport:8009/;    
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header authorization $http_authorization;
            proxy_cookie_path /project /proxy_path;
        }
        
        # 网关
        location /api/ {
            proxy_pass http://pangea-gateway:9527/;    
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header authorization $http_authorization;
            proxy_cookie_path /project /proxy_path;
        }
        
        # 国际化
        location /intl/ {
            proxy_pass http://pangea-gateway:9527/;    
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header authorization $http_authorization;
            proxy_cookie_path /project /proxy_path;
        }
        
         # 流程
         location /api/act/ {
             proxy_pass http://flowable:8007/flowable/;    
             proxy_set_header Host $host;
             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
             proxy_set_header authorization $http_authorization;
            proxy_cookie_path /project /proxy_path;
         }
        location /flowable_idm {
                 proxy_pass http://flowable:8007/flowable;
                 proxy_cookie_path  /flowable  /flowable_idm;
             }
        location /flowable_task {
                 proxy_pass http://flowable:8007/flowable;
                 proxy_cookie_path  /flowable  /flowable_task;
          }
        location /flowable_admin {
                proxy_pass http://flowable:8007/flowable;
                proxy_cookie_path  /flowable  /flowable_admin;
          }
        location /flowable_modeler {
                 proxy_pass http://flowable:8007/flowable;
                 proxy_cookie_path  /flowable  /flowable_modeler;
             }
    
        # 鉴权
        location /auth/ {
            proxy_pass http://pangea-gateway:9527;    
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header authorization $http_authorization;
            proxy_cookie_path /project /proxy_path;
        }
    
        # 永洪报表
        location /bi {
            proxy_pass http://yhbi.hisense.com:8888;
        }
        
        # minio
        location /minio/ {
            proxy_pass minio地址/;
        }
    }
  2. 搭载位置/etc/nginx/nginx.conf

    bash
    user  nginx;
    worker_processes  1;
    
    error_log  /var/log/nginx/error.log warn;
    pid        /var/run/nginx.pid;
    
    
    events {
        worker_connections  1024;
    }
    
    
    http {
        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"';
    
        access_log  /var/log/nginx/access.log  main;
    
        sendfile        on;
        #tcp_nopush     on;
    
        keepalive_timeout  65;
    
        gzip on;
        gzip_min_length 1k;
        gzip_buffers 8 16k;
        gzip_comp_level 4;
        gzip_types application/x-javascript  application/javascript  text/css text/javascript image/jpeg image/gif image/png image/x-icon;
        gzip_vary on;
        gzip_disable "MSIE [1-6]\.";
    
        include /etc/nginx/conf.d/*.conf;
    }

参考内容