/

NGINX 前后端分离配置

前后端分离的开发已是主流,本文主要是记录前后端分离项目的 NGINX 配置。

  • 前端 Vue web 入口 host.test
  • 后端 PHP Yii service 入口 host.test/api
server {
listen 80;
server_name host.test;
root /data/project/;
index index.html index.php;

location ^~ /api {
root /data/project/service/web/;
fastcgi_pass 127.0.0.1:9000;
include fastcgi.conf;
fastcgi_param SCRIPT_FILENAME /data/project/service/web/index.php;
fastcgi_param SCRIPT_NAME /api/index.php;
access_log logs/service-access.log;
error_log logs/service-error.log;
}

location ^~ / {
alias /data/project/web/dist/;
access_log logs/web-access.log;
error_log logs/web-error.log;
}
}