我有一个api,它是主站点的独立代码库。
它有一个单独的nginx配置,当我使用api.mydomain.test/api/v1/
访问它时可以正常工作。
但是我想使用网站网址来访问api代码。
我的nginx配置:
server {
server_name .mydomain.test;
root "/c/Users/Me/Homestead/site/public"
index index.html index.html index.php;
location ~* /api/(v[0-9]+)/ {
root "/c/Users/Me/Homestead/api/$1/public";
try_files $uri $uri/ /index.php?$query_string;
error_log /var/log/nginx/mydomain.test-error.log debug;
}
location / {
try_files $uri $uri/ /index.php?$query_string;
error_log /var/log/nginx/mydomain.test-error.log debug;
}
}
使用此配置转到mydomain.test
工作正常但mydomain.test/api/v1/
重定向到mydomain.test/index.php
文件。
调试日志如下所示:
2018/01/03 12:25:57 [debug] 6669#6669: *10 http cl:-1 max:104857600
2018/01/03 12:25:57 [debug] 6669#6669: *10 rewrite phase: 3
2018/01/03 12:25:57 [debug] 6669#6669: *10 post rewrite phase: 4
2018/01/03 12:25:57 [debug] 6669#6669: *10 generic phase: 5
2018/01/03 12:25:57 [debug] 6669#6669: *10 generic phase: 6
2018/01/03 12:25:57 [debug] 6669#6669: *10 generic phase: 7
2018/01/03 12:25:57 [debug] 6669#6669: *10 access phase: 8
2018/01/03 12:25:57 [debug] 6669#6669: *10 access phase: 9
2018/01/03 12:25:57 [debug] 6669#6669: *10 access phase: 10
2018/01/03 12:25:57 [debug] 6669#6669: *10 access phase: 11
2018/01/03 12:25:57 [debug] 6669#6669: *10 post access phase: 12
2018/01/03 12:25:57 [debug] 6669#6669: *10 try files phase: 13
2018/01/03 12:25:57 [debug] 6669#6669: *10 http script var: "/api/v1/"
2018/01/03 12:25:57 [debug] 6669#6669: *10 trying to use file: "/api/v1/" "/c/Users/Me/Homestead/api/v1/public/api/v1/"
2018/01/03 12:25:57 [debug] 6669#6669: *10 http script var: "/api/v1/"
2018/01/03 12:25:57 [debug] 6669#6669: *10 trying to use dir: "/api/v1/" "/c/Users/Me/Homestead/api/v1/public/api/v1/"
2018/01/03 12:25:57 [debug] 6669#6669: *10 http script copy: "/index.php?"
2018/01/03 12:25:57 [debug] 6669#6669: *10 trying to use file: "/index.php?" "/c/Users/Me/Homestead/api/v1/public/index.php?"
2018/01/03 12:25:57 [debug] 6669#6669: *10 internal redirect: "/index.php?"