猿问

Nginx如何使用一个域名配置多个目录

server{
listen*:80;
server_nameadmin.hiphop.top;
location/{
root"D:\Office\PHPStudy\PHPTutorial\WWW\MyWork\VhiphopAdmin\dist";
indexindex.html;
try_files$uri$uri//index.html;
}
location/api{
root"D:\Office\PHPStudy\PHPTutorial\WWW\MyWork\VhiphopAdminApi\public";
indexindex.php;
try_files$uri$uri//index.php?$query_string;
}
location~\.php(.*)${
fastcgi_pass127.0.0.1:9000;
fastcgi_indexindex.php;
fastcgi_split_path_info^((?U).+\.php)(/?.+)$;
fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;
includefastcgi_params;
}
}
配置代码如上访问admin.hiphop.top可以匹配到"D:OfficePHPStudyPHPTutorialWWWMyWorkVhiphopAdmindist"
访问admin.hiphop.top/api不能匹配到"D:OfficePHPStudyPHPTutorialWWWMyWorkVhiphopAdminApipublic"
dist目录是我的前端静态文件,public目录是phpapi接口的入口目录请问如何配置才能做到访问admin.hiphop.top/*时匹配dist目录并且访问admin.hiphop.top/api优先匹配php的public目录
配置2个域名是没问题的因为浏览器有跨域问题,所以现在想只用一个域名
UYOU
浏览 5269回答 2
2回答

九州编程

问题已经解决了在最后一个.php匹配规则里面加上root就可以了location~\.php(.*)${root"D:\Office\PHPStudy\PHPTutorial\WWW\MyWork\VhiphopAdminApi\public";indexindex.php;fastcgi_pass127.0.0.1:9000;fastcgi_indexindex.php;fastcgi_split_path_info^((?U).+\.php)(/?.+)$;fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;includefastcgi_params;}
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答