background
Recently received a project, there is such a demand, need to download some files and preview permission control, only allow members to use, after looking for some information and finally decided to use Nginx with Java service to achieve this function.
Use this method only for some business files, and do not use this method for static files in web pages, so as not to increase the burden on the server
Configure Nginx
Use in configurationNginx
A port is opened for8086
File server, added in configurationinternal
Property indicating that the file is internally accessible only. Upon receiving the request, the proxy forwards the request to port as8080
theJava
Permission authentication service.
This is basically all the configuration for Nginx. It’s not very complicated. Remember to restart the configuration to make sure it works.
Java service
The background to useSpringBoot
Set up the service and pass the Settings after being certifiedResponseHeader
noticeNginx
Whether to return the requested file.
- Content-Type
- Content-Disposition
- X-Accel-Redirect
Three main headers
More about the header
The complete code