前端利用nginx解决js跨域的问题

2019-01-06  本文已影响22人  牧馬放飏

1.安装nginx

参考:https://www.jianshu.com/p/fabf07468e33

2.修改nginx.conf文件

    server {
        listen       8090;
        server_name  localhost;

        #charset koi8-r;
        #access_log  logs/host.access.log  main;

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

        #error_page  404              /404.html;
        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        # 代理的关键
        location /apis {
            # 添加访问目录为/apis的代理配置
            rewrite  ^.+apis/?(.*)$ /$1 break;
            include  uwsgi_params;
            proxy_pass   http://bms.test.com;
        }

    }

配置解释:

3.重新启动nginx

sudo nginx -s reload
上一篇 下一篇

猜你喜欢

热点阅读