7-ThingsBoard 前后端分离后部署到nginx

1.项目根目录执行 ng build 生成编译后文件在 targetgenerated-resourcespublic 下
2. 配置nginx

#user  nobody;
worker_processes  1;
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    proxy_hide_header X-Powered-By;
    proxy_hide_header Server;
    #access_log  logs/access.log  main;
    sendfile        on;
    #tcp_nopush     on;
    #keepalive_timeout  0;
    keepalive_timeout  65;
    autoindex on;    #自动索引
    #gzip  on;

    #后端服务器,配置多个ip可做集群
    upstream ecloud-iot-server {
        server localhost:8080;
    }
    upstream ecloud-iot-server-ws{
    server localhost:8080;
    }
    server {
    server_tokens off;
        listen       8081;
        server_name  localhost;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        #项目文件映射
        location / {
            alias  D:/nginx-1.16.1/html/xxx/public/;
            try_files $uri $uri/ /index.html =404;
        }
    
        #转发api
        location /api  { 
            proxy_redirect off;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass http://xxx-server; 
        }

        #转发api
        location /static/rulenode { 
            proxy_redirect off;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass http://xxx-server; 
        }
                #转发api
        location /assets/help/*/rulenode/** { 
            proxy_redirect off;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass http://xxx-server; 
        }

            location    /static/widgets { 
            proxy_redirect off;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass http://xxx-server; 
        }

                location        /oauth2 { 
            proxy_redirect off;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass http://xxx-server; 
        }
                location        /login/oauth2 { 
            proxy_redirect off;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass http://xxx-server; 
        }
    # 所有请求都转发
        location /api/ws {
                    # 转发websocket需要的设置
            proxy_set_header X-Real_IP $remote_addr;
            proxy_set_header Host $host;
            proxy_set_header X_Forward_For $proxy_add_x_forwarded_for;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_pass http://xxx-server-ws;
        
        }
        #error_page  404              /404.html;
        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

}


本文章来源于互联网,如有侵权,请联系删除!原文地址:7-ThingsBoard 前后端分离后部署到nginx

相关推荐: 工业互联网的逻辑到底是什么

工业互联网,是相对“消费互联网”提出的概念。在消费互联网时期,互联网技术已经初步展现了其技术魅力,既创造了巨大的经济价值,又再次点燃了人类对于社会变革的梦想。正是由于消费互联网的巨大魅力,在工业互联网概念产生之后,人类社会也对工业互联网寄予了巨大的厚望。 文/…