我是REST API开发的新手,
我有3个小的java项目,每个项目都有一些API。
示例网址:
https://example.com/project1/rest/class1/api_name1
https://example.com/project1/rest/class2/api_name2
https://example.com/project2/rest/class3/api_name3
https://example.com/project2/rest/class4/api_name4
https://example.com/project3/rest/class5/api_name5
https://example.com/project3/rest/class5/api_name6
每个网址都不同,我希望每个API都有基本网址 像这样的东西
https://example.com/something_common/api_name1
https://example.com/something_common/api_name2
https://example.com/something_common/api_name3
https://example.com/something_common/api_name4
https://example.com/something_common/api_name5
https://example.com/something_common/api_name6
我的问题是,它是否可能,如果是,那该怎么办? 提前致谢
答案 0 :(得分:1)
你可以这样做:
如果您使用Apache,请检查How To Use Apache HTTP Server As Reverse-Proxy Using mod_proxy Extension。在您的情况下,它看起来像:
ProxyPass /something_common/api_name1 http://127.0.0.1:8080/project1/rest/class1/api_name1
或Nginx - 请检查Understanding Nginx HTTP Proxying, Load Balancing, Buffering, and Caching或Virtual Hosts on nginx (CSC309):
location /something_common/api_name1 {
proxy_pass http://localhost:8080/project1/rest/class1/api_name1;
proxy_request_buffering off;
}