nginx实现简单的反向代理

一、去nginx官网下载nginx相应的版本

二、打开nginx下的conf目录下的nginx.conf文件,并备份此文件一份

三、把nginx.conf的内容修改如下:


#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}

http {  
      include       mime.types;  
      default_type  application/octet-stream;  
      #开启gzip模块
      gzip on;
      sendfile        on; 
      keepalive_timeout  65;
   include proxy.conf;  #要配置的反向代理文件
 }

四、在通一目录下建立proxy.conf文件

proxy.conf文件内容配置如下:

upstream www.youhua.com{   
        server 11.28.85.159:8083 weight=1;    

        #server 192.168.10.2 weight=1; 
                                }
      server {    #Nginx代理服务器      
      listen       8089;        
        server_name  www.youhua.com;     
        location / {        
          root   html;        
          index  index.html index.htm;  
          proxy_pass  http://www.youhua.com;    
          proxy_redirect  default;     
                    }       
      error_page   500 502 503 504  /50x.html;  
     location = /50x.html
                 {          
   root   html;    
                 }  
        }
  

原文地址:https://www.cnblogs.com/zhangkjun/p/2149662.html