ngnix配置

来源:互联网 发布:苹果微信数据损坏失败 编辑:程序博客网 时间:2024/05/18 00:39

现在的项目开发,大多数都是前后端分离的,所以难免会遇到跨域的问题,这时候就需要使用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;
        }
    }
}

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

原创粉丝点击