ngnix配置

现在的项目开发,大多数都是前后端分离的,所以难免会遇到跨域的问题,这时候就需要使用ngnix来转发

首先,配置文件结构如下:
主要我们需要配置的地方是server,server里面的listen是需要监听的端口,location 配置的是url的路径,比如:

location /{

root   F:/LinkCM_WorkSpace/opp-gjyjb-web/;
        index  index.html index.htm;

}

而proxy_pass是转发到的地址,如下:

location /dss-opp-base/ {
proxy_pass http://localhost:8080;
proxy_connect_timeout 50s;
#proxy_read_timeout 20s;
}


意思是,当你以/结尾的url请求时,回去root路径下找名称为index的文件

worker_processes  1;

events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

server {
        listen       5008;
        server_name  localhost;


        location / {
            root   F:/LinkCM_WorkSpace/base-opp-web/;
            index  index.html index.htm;
}
location /dss-opp-base/ {
proxy_pass http://localhost:8080;
proxy_connect_timeout 50s;
#proxy_read_timeout 20s;
}
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

server {
        listen       5009;
        server_name  localhost;


        location / {
            root   F:/LinkCM_WorkSpace/opp-gjyjb-web/;
            index  index.html index.htm;
}
location /opp-gjyjb/ {
proxy_pass http://localhost:8080;
proxy_connect_timeout 50s;
#proxy_read_timeout 20s;
}

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

server {
        listen       5010;
        server_name  localhost;


        location / {
            root   F:/LinkCM_WorkSpace/base-opp-web-springmvc/;
            index  index.html index.htm;
}
location /opp-server/ {
proxy_pass http://localhost:8090;
proxy_connect_timeout 50s;
#proxy_read_timeout 20s;
}

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

不喜勿喷,只是记录一下自己的心得。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值