通过NGINX location实现一个域名访问多个项目

 

location ~ \.php$ {
  root /home/webroot;    //此目录下有多个项目 project1 ,project2...
  fastcgi_pass $php_upstream;
  fastcgi_index index.php;
  include fastcgi.conf;
}

location ~/project1 {
  index index.php;
  fastcgi_pass $php_upstream;
  include fastcgi.conf;
  rewrite ^/(project1)(/[^\?]*)?((\?.*)?)$ /project1/index.php$2$3 break;
}

location ~/project2 {
  index index.php;
  fastcgi_pass $php_upstream;
  include fastcgi.conf;
  rewrite ^/(project2)(/[^\?]*)?((\?.*)?)$ /project2/index.php$2$3 break;
}

include vhost/site4project1.rewrite;

include vhost/site4project2.rewrire;

site4project1.rewrite文件内容:rewrite ^/project1/api/resource/create$ /project1/api/resource_create break;

site4project2.rewrite文件内容:rewrite ^/project2/api/resource/create$ /project2/api/resource_create break;

posted @ 2019-07-09 11:06  花泪哲  阅读(4411)  评论(0编辑  收藏  举报