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。


版权声明:本文为weixin_43612925原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。