当前位置: 移动技术网 > 科技>操作系统>Linux > nginx下根据指定路由重定向

nginx下根据指定路由重定向

2019年02月14日  | 移动技术网科技  | 我要评论

  前言:

  最近在搭建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.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;
    }    

 

  

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网