window下Nginx的常用配置方法

1.默认配置

   server {
        listen       88;
        server_name  localhost;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        location / {
            root   html;
            index  index.html index.htm;
        }
        #后面还有其他配置,我只截取了这些...
    }

2.常用命令

启动服务:start nginx
退出服务:nginx -s quit
强制关闭服务:nginx -s stop
重载服务:nginx -s reload  (重载服务配置文件,类似于重启,服务不会中止)

3.配置多个端口方法

访问页面时 域名+端口

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

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

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

如 需要配置后端地址
后端监听 dev-api 的前缀 就会进入到

location /dev-api/ {
            proxy_pass              http://127.0.0.1:8088/;
            proxy_set_header        Host 127.0.0.1;
            proxy_set_header        X-Real-IP $remote_addr;
            proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
           add_header 'Access-Control-Allow-Origin' "$http_origin";
           add_header 'Access-Control-Allow-Credentials' "true";
}

4.配置在监听80端口 部署多套前端项目

好处 访问项目不会暴露端口

1) 这是通过ip域名映射方法

在hosts文件中新增ip域名映射

127.0.0.1 webone.com
127.0.0.1 webtwo.com
127.0.0.1 webthree.com

server {
    listen       80;   #注意这里,要把默认的那个default_server去掉,因为我们在下面要单独配置域名访问,所以这里不要留default_server,不然会报错。
    server_name  webone.com;  #这里写你想设置的域名,可以写多个,与名之间用空格隔开
    # root         D:/me/nginx/nginx-1.15.7;   #这里是你虚拟机的根目录,写绝对路径
    # Load configuration files for the default server block.
 
    location / {
        root   html/web1;
        index  index.php index.html index.htm;  #这里配置默认访问的页面
    }
}
 
server {
    listen       80;
    server_name  webtwo.com;
    root         D:/me/nginx/nginx-1.15.7; 
 
    location / {
        root   html/web2;
        index  index.php index.html index.htm; 
    }
}
 
server {
    listen       80;
    server_name  webthree.com;
    root         D:/me/nginx/nginx-1.15.7;  
 
    location / {
        root   html/web3;
        index  index.php index.html index.htm;  
    }
}
 
 

2) 可以通过 访问路径 进入
如 域名:80 /dist1 /dist2 /dist3
 


server {
    listen       80;
    server_name  webtwo.com;
    root         D:/me/nginx/nginx-1.15.7; 
 
    location /dist1 {
        root   html/web1;
        index  index.html index.htm;
    }

    location /dist1 {
        root   html/web2;
        index  index.html index.htm;
    }

    location /dist3 {
        root   html/web3;
         index  index.html index.htm;
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值