当前位置:   article > 正文

Nginx部署前端,单个项目部署和多个项目部署_nginx配置多个前端项目

nginx配置多个前端项目

单个项目的部署

下载nginx包
下载:nginx下载地址

解压nginx包

在这里插入图片描述

html是放打包后的文件

在这里插入图片描述

conf里的nginx.conf是nginx的配置

vue项目打包

本地的配置:(打包后在nginx的nginx.conf中配置)

在这里插入图片描述

打包时注意的配置:(读取静态资源)
在这里插入图片描述
设置成发布的地址:
在这里插入图片描述
nginx.conf的配置

配置服务名,端口和代理地址
在这里插入图片描述

location ^~/dldz/ {
            proxy_pass   http://203.49.10.44:9010/fhzs/;
            add_header Access-Control-Allow-Origin *;
            add_header Access-Control-Allow-Credentials true;
            add_header Access-Control-Allow-Methods *;
            add_header Access-Control-Allow-Headers *;
            rewrite ^(.*)tzlh(.*)$  $1/$2; break;
            index index.html index.htm;

        }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

多个项目的部署

nginx解压后在htnl文件夹下建立两个文件夹

在这里插入图片描述

vue项目打包

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

nginx.conf的配置

在这里插入图片描述
在这里插入图片描述

location / {
            root   html/nb;
            index  index.html index.htm;
        }

        location /lh {
             alias   html/lh;
             try_files $uri $uri/ /lh/index.html;
             index  index.html index.htm;
        }

        location @router {
            rewrite ^.*$ /index.html break;
        }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
location ^~/dldz/ {
            proxy_pass   http://220.191.246.54:7010/channel/9by4JHpCmg/;
            add_header Access-Control-Allow-Origin *;
            add_header Access-Control-Allow-Credentials true;
            add_header Access-Control-Allow-Methods *;
            add_header Access-Control-Allow-Headers *;
            index index.html index.htm;

        }

        location ^~/tzlh/ {
            proxy_pass   http://220.191.246.54:7010/channel/9by4JHpCmg/fhzs/;
            add_header Access-Control-Allow-Origin *;
            add_header Access-Control-Allow-Credentials true;
            add_header Access-Control-Allow-Methods *;
            add_header Access-Control-Allow-Headers *;
            # rewrite ^(.*)tzlh(.*)$  $1/$2; break;
            index index.html index.htm;
        }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/232360
推荐阅读
相关标签
  

闽ICP备14008679号