Nginx 的反向代理

#user  nobody;
worker_processes  1;                                                                    //配置文件主要有events块和http块组成,在http块中又包含upstream和server,在server中又包括location块

#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;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;
    //负载均衡
        upstream myserver {                //浏览器通过172.20.248.117:9001 轮训访问8080和8081  
      server 127.0.0.1:8080 weight =10;
      server 127.0.0.1:8081 weight = 5;
      //ip_hash

     }
    <!--1轮询 默认的请求是轮询每一个服务器,如果有一个服务地挂了,自动回剔除
      2.权重 在ip后面加上 weight=数字 数字越大,权重越大,访问次数越高
      3.ip_hash: 每一个clien固定访问一个服务器,可以解决session共享问题.
      4.fair(第三方) 更加服务器的相应时间 响应时间越短,越容易被请求
    -->
    server { listen 9001; server_name 172.20.248.117; #charset koi8-r; #access_log logs/host.access.log main;

     
     location / {
        proxy_pass http://myserver;
      }
//方向代理 // location
~/t1/ { // root html; // proxy_pass http://127.0.0.1:8080; // index index.html index.htm; // } // location ~/t2/ { // proxy_pass http://127.0.0.1:8081; // } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443 ssl; # server_name localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #} }

 

1.在linux上面部署两个tomcat :

修改tomcat中的配置文件,修改这三个地方的端口号

 

 

 

 

 

 2.配置nginx的配置环境

 

posted @ 2019-09-29 13:51  霍宇飞  阅读(128)  评论(0编辑  收藏  举报