美文网首页
7-ThingsBoard 前后端分离后部署到nginx

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

作者: 崔寒冰 | 来源:发表于2021-11-03 15:48 被阅读0次
    1.项目根目录执行 ng build 生成编译后文件在 target\generated-resources\public 下
    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

          本文链接:https://www.haomeiwen.com/subject/bhhczltx.html