nginx下根据指定路由重定向

  前言:

  最近在搭建vue后台,后端接口是PHP写的,线上构建好之后,需要请求其他域名下的接口,开发环境已经使用proxytable解决了接口问题,为了开发和生成的代码一致,

编译后的代码,放在nginx下运行,配置了路由重写。

  项目说明:

前端页面域名 front.me,后端接口backend.me,前端访问后端接口都是请求front.me/api/controller/action,nginx配置了重定向,当检测到路由里面/api/是会重定向到 backend.me/controller/action,下面是完整配置,其中重定向配置,我加了说明

  

server
    {
        listen 9929 default_server;
        server_name _;
        index index.html index.htm index.php;
        root  /data/web/eyeSkyAdmin/dist;
        include enable-php-pathinfo.conf;
        location /nginx_status
        {
            stub_status on;
            access_log   off;
        }

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }

        location ~ .*\.(js|css)?$
        {
            expires      12h;
        }

        location ~ /.well-known {
            allow all;
        }

        location ~ /\.
        {
            deny all;
        }
        #这段是指定路由重定向配置start
        location /api/{
            rewrite ^/proxy/html/(.*)$ /$1 break;
            proxy_pass http://backend.me/;
        }
        #这段是指定路由重定向配置end
        access_log  /home/wwwlogs/access.log;
    }    

 

  

posted @ 2019-02-13 10:29  StudyBlog  阅读(5505)  评论(0编辑  收藏  举报