nginx 部署多个项目 的两种方式

1.多个端口形式 ,nginx 默认代理80 端口 ,我们可以把其他项目部署到其他端口

修改 nginx.conf  我的在 usr/local/nginx/conf/nginx.conf    修改 vim nginx.conf 

在http 模块内加上一行命令   include /etc/nginx/conf.d/*.conf;  可以自定义路径保持一致就行,这个就像子组件一样 ,当nginx执行 nginx.conf  时 ,会加载 include /etc/nginx/conf.d 文件下的 所有 conf 配置文件,我们在 这些文件可以写 nginx.conf 相同的内容。 nginx.conf 默认代理的是 80 端口,我们可以 在 子文件  conf 中代理其他的端口 

nginx.conf


#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;
    include /etc/nginx/conf.d/*.conf;
   
    sendfile        on;

    keepalive_timeout  65;
    
    server {
        listen       80;
        server_name  localhost;
        gzip on;
        gzip_min_length 1k;
        gzip_comp_level 9;
        gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
        gzip_vary on;
        gzip_disable "MSIE [1-6]\.";
       
        
        location / {
            root   html/dist;
            index  index.html index.htm;
         }
         
          location /cn {
            alias   html/en;
            index  index.html index.htm;
         }
         
        
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

      

    }

}

/etc/nginx/conf.d/cn.conf

server {
    listen       81;
    server_name  localhost;
 
    
 
    location / {
          root   html/cn;
          index  index.html index.htm;
        }
 
   
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
 
   
}

效果

第一个使用 默认 80 端口 , 第二个使用路由 ,第三个使用 81端口

我的所有项目 都在 usr/local/nginx/html 中 ,当你使用 路由形式 要 修改 项目打包 时的配置 

vue.config.json 配置项  加上  publicPath  和 vue-router 添加 base配置项 

module.exports = defineConfig({
  publicPath:'/cn/',
  transpileDependencies: true,
  lintOnSave: false,
  ....

})
let router = new VueRouter({
  routes,
  base:'/cn/'
});

 添加的名称 就是需要 在地址栏访问的 字段

root和 alias的区别 

请求 /a

root html/b  指向 html/b/a

alias html/b   指向 html/b 

  • 0
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值