Nginx部署多个web项目Windows

Nginx部署多个web项目Windows

前言

​ Nginx可以通过三种修改nginx.conf配置文件的方式部署web项目,其中有点要注意

Windows的文件路径需要反义D:\Java\nginx-1.20.1\htmls;

1、域名配置


    server {
        listen       80;
        server_name  xys;         //可以通过修改域名达到目的
       
       location / {
            root   html;
            index  index.html index.htm;
        }
    }
    
    server {
        listen       80;
        server_name  ld;         //可以通过修改域名达到目的
       
       location / {
            root   D:\Java\\nginx-1.20.1\\htmls;
            index  index.html index.htm;
        }
    }

2、端口配置

server {
        listen 8000;
        
        location / { 
                root html;
                index index.html;
        }
}

# nginx 80端口配置 (监听a二级域名)
server {
        listen  80;
        server_name a.fly.com;
        
        location / {
                proxy_pass http://localhost:8000; #转发
        }
}

server {
        listen 8001;
        
        location / { 
                root   D:\Java\\nginx-1.20.1\\htmls;
                index index.html;
        }
}

# nginx 80端口配置 (监听b二级域名)
server {
        listen  80;
        server_name b.fly.com;
        
        location / {
                proxy_pass http://localhost:8001; #转发
        }
}

可以看出配置两个项目需要配置4个server,过于麻烦,不建议

3、location配置

server {
        listen       80;
        server_name  localhost;
        location / {
            root   html;
            index  index.html index.htm;
        }

        location /boke {
            alias   D:\Java\\nginx-1.20.1\\htmls;
            index  index.html index.htm;
        }

注意: 这种方式配置的话,location / 目录是root,其他的要使用alias。

  • 5
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

芝兰生于深谷

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值