前后端分离之项目部署

发布于 2021-05-21 17:49 阅读 1816

前后端分离的架构模式被越来越多的中大型项目所采用,这就给项目部署提出了要求

需求

假如有这么一个系统

  • 用户端:提供给用户浏览的(纯前端项目,http://xx.com
  • 管理员端:供作者维护这个系统(纯前端项目,http://xx.com/admin
  • 服务端:为用户端和管理员端提供接口(纯后端项目,http://xx.com/api

nginx配置

xx.com.conf

server {
    listen       80;
    server_name  xx.com; # 用户端
    index index.php index.htm index.html default.html;
    root      /data/www/shop-h5/web;

    # 服务端
    location /api {
        proxy_pass   http://127.0.0.1:8089/;
        include conf.d/proxy.md;
    }
    # 管理员端
    location /admin/ {
        alias  /data/www/shop-admin/web/;
        break;
    }

}

xx8089.conf

server {
    listen 8089;
    index default.html index.htm index.html index.php; 
    root /data/www/shop/web;

    rewrite ^/admin/(.*)$ /admin.php/admin/$1 last;
    rewrite ^/user/(.*)$ /user.php/user/$1 last;

    location ~ \.php {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_split_path_info ^((?U).+.php)(/?.+)$;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param ENV_MODE production;
        include        fastcgi_params;
    }

}

广而告之,我的新作品《语音助手》上架Google Play了,欢迎下载体验