功能:利用Nginx实现端口转发
Nginx设置
修改Nginx解压后的conf目录下的nginx.conf文件,在其中添加内容:
location /api/ {
proxy_pass http://127.0.0.1:9999/;
}
如下图所示:
测试服务器
@RestController
public class UserController {
@PostMapping("/fun")
public String fun(){
System.out.println("fun");
return "fun";
}
}
注:假设其请求地址:http://localhost:9999/fun
使用postman测试
- 正常访问:
- 不带端口访问
- 跨域端口转发