Nginx 前后端分离,前端手机端与PC端分离

前后端分离,前端手机端与PC端分离

server {
    listen       8080;
    server_name  localhost 127.0.0.1;

    #添加头部信息
    proxy_set_header Cookie $http_cookie;
    proxy_set_header X-Forwarded-Host $host;
    proxy_set_header X-Forwarded-Server $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    #add_header Cache-Control no-cache;
    
    location /api {
        rewrite /api/(.*) /$1 break;
        proxy_pass http://localhost:9090;
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host:$server_port; #重点重定向会导致oAuth2找不到正确的重定向地址
    }

    location / {
        #rewrite /ui/(.*) /$1 break;
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host:$server_port; #重点重定向会导致oAuth2找不到正确的重定向地址
        if ($http_user_agent ~* (mobile|nokia|iphone|ipad|android|samsung|htc|blackberry)) {
            proxy_pass http://localhost:4535;
            break;
        }
        proxy_pass http://localhost:4534;
    }
}

 

posted @ 2022-06-19 21:26  三瑞  阅读(163)  评论(0编辑  收藏  举报