You can not select more than 25 topics 
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long. 
		
		
		
		
		
			
	
	
		
			
	
		
			This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
		 
	
		
		
			
				
				
					
						
						
						
							---
 
						
						
						
							layout: post
 
						
						
						
							title: 如何用PHP制作一个简单的反向代理
 
						
						
						
							tags: [PHP, 代理]
 
						
						
						
							---
 
						
						
						
							
 
						
						
						
							  解决问题还是很简单的。<!--more-->     
 
						
						
						
							
 
						
						
						
							# 起因
  
						
						
						
							, , , , ,  
						
						
						
							  在两年前, , , , , , , ,  
						
						
						
							  这时候我就想到了PHP, ,  
						
						
						
							  
 
						
						
						
							# 解决过程
  
						
						
						
							, , , ,  
						
						
						
							  我用的是GearHost的虚拟主机, , , ,  
						
						
						
							  把下面的代码放到Rewrite的rules段里就可以正常工作了:  
						
						
						
							```xml
  
						
						
						
							<rule  name= "Mayx"  stopProcessing= "true" > 
 
						
						
						
							<match  url= "^(.*)$"  /> 
 
						
						
						
							<conditions> 
 
						
						
						
							<add  input= "{REQUEST_FILENAME}"  matchType= "IsFile"  negate= "true"  /> 
 
						
						
						
							<add  input= "{REQUEST_FILENAME}"  matchType= "IsDirectory"  negate= "true"  /> 
 
						
						
						
							</conditions> 
 
						
						
						
							<action  type= "Rewrite"  url= "index.php" /> 
 
						
						
						
							</rule> 
 
						
						
						
							``` 
 
						
						
						
							  然后就是新建一个index.php文件,  
						
						
						
							  不过如果直接用`echo file_get_contents(url)`的方法搞会出现一些问题, ,  
						
						
						
							  后来我花了2个小时查资料, , , , , , , , , , , , :  
						
						
						
							```php
  
						
						
						
							<? php 
 
						
						
						
							$content = file_get_contents ( "https://mabbs.github.io" . $_SERVER [ 'REQUEST_URI' ]); 
 
						
						
						
							foreach ( $http_response_header  as  $header ){ 
 
						
						
						
							header ( $header ); 
 
						
						
						
							} 
 
						
						
						
							if ( $content ){ 
 
						
						
						
							echo  $content ; 
 
						
						
						
							} else { 
 
						
						
						
							echo  "404" ; 
 
						
						
						
							} 
 
						
						
						
							``` 
 
						
						
						
							
 
						
						
						
							# 之后的操作
  
						
						
						
							, , ,