Because the project needs to implement a domain name proxy function
For example:
The code is as follows: |
Copy code |
A.com/a.html=> B .com/ B .html
|
That is to say, I used a.com to proxy the B .com website request. After a friend introduced it, I used apache's reverse proxy to achieve this goal. It was really nice to have a try. configuration is also super convenient.
(Note that the following section only describes reverse proxy and forward proxy. I will introduce it later)
1. Start the mod_proxy module of apache.
The code is as follows: |
Copy code |
LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_http_module modules/mod_proxy_http.so |
Note: mod_proxy_http.so. During the test, the agent fails if I didn't add this module. After I add this module, the problem disappears.
2. Implement proxy statements
The code is as follows: |
Copy code |
ProxyPass/mirror/foo/http://backend.example.com/
|
All requests under the current host/mirror/foo/directory are distributed to backend.example.com.
According to my requirements:
Add
The code is as follows: |
Copy code |
Http:// B .com/ProxyPass/
|
Everything OK
3. After domain name proxy, note the following:
3.1: it is best to use relative paths for URLs on websites. If absolute paths are used, the proxy is easily bypassed, and the hosts behind the proxy server are easily exposed.
3.2: note that when referencing the global variable $ __server ['server _ name'], the domain name of the current server_name is obtained. if you want to obtain the proxy domain name, you need to get the proxy domain name through $ __server ['http _ X_FORWARDED_FOR. note: it is generally used for operations such as cookie writing.