Heim  >  Artikel  >  Backend-Entwicklung  >  Nginx 反向代理 Demo

Nginx 反向代理 Demo

WBOY
WBOYOriginal
2016-08-08 09:19:141324Durchsuche

关于Nginx的基础理解,淘宝的文档已经介绍很清楚了:http://tengine.taobao.org/book/
以下记录些具体的使用流程,方便日后查看

一. 整体配置步骤:

  1. 安装Nginx。
    1. 安装依赖包,包括 pcre 以及 zlib 依赖。centos7的 root 权限下 yum list 搜索,再安装。
    2. 下载Nginx。./configure ---> make ---> make install.(安装成功看提示就知道安装在哪,一般在/usr/local/nginx)
    3. 访问 wget 127.0.0.1 即可看到安装成功。 
  2. 准备一个机子放Web应用,例如我的应用地址为 192.168.1.99.157:8081/springmvc。再准备一个机子(我的安装Nginx的机子的IP为192.168.199.176)安装上述的Nginx(其实你用同一个机子也是可以测试的,用不同的 端口当做不同的机子)
  3. 在安装了Nginx的机子上修改nginx.conf主配置文件。例如如下的配置文件(测试版):
    1.  

      worker_processes 2;

       

      events {

      worker_connections 1024;

      }

       

      http {

      server_tokens off;

      include mime.types;

      default_type application/octet-stream;

      charset utf-8;

       

      server_names_hash_bucket_size 128;

      client_header_buffer_size 32k;

      large_client_header_buffers 4 32k;

      client_max_body_size 300m;

      tcp_nopush on;

      tcp_nodelay on;

      client_body_buffer_size 512k;

      proxy_connect_timeout 300s;

      proxy_read_timeout 300s;

      proxy_send_timeout 300s;

      proxy_buffer_size 64k;

      proxy_buffers 4 32k;

      proxy_busy_buffers_size 64k;

      proxy_temp_file_write_size 128k;

      proxy_ignore_client_abort on;

      gzip on;

      gzip_http_version 1.1;

      gzip_min_length 1k;

      gzip_buffers 4 16k;

      gzip_types text/plain application/x-javascript text/css application/xml;

      gzip_comp_level 2;

      gzip_vary on;

       

      log_format main '$remote_addr - $remote_user [$time_local] "$request" '

      '$status $body_bytes_sent "$http_referer" '

      '"$http_user_agent" "$http_x_forwarded_for"';

       

      upstream apm {

      server 192.168.199.157:8081;

      }

      server {

      listen 8080;

      server_name 192.168.199.176;

      charset utf-8;

      location /springmvc/ {

      proxy_pass http://apm;

      }

      }

       

      sendfile on;

      keepalive_timeout 65;

      }

  4. 访问 192.168.199.176:8080/springmvc/ 时,成功访问到 192.168.199.157:8081/springmvc 的首页

版权声明:本文为博主原创文章,未经博主允许不得转载。

以上就介绍了Nginx 反向代理 Demo,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn