NG 转发配置

ng的用途就不用说了,反向代理么,都知道,不过以前一直不太理解怎没配,现在终于理解点了

1.下载ng,如图:

2.先解压,解压后的路径不建议有空格和中文,其次配置环境变量,加到系统path

3.启动ng win+R---->cmd---->start nginx

4.修改配置文件

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

     sendfile        on;
   
    keepalive_timeout  65;

    gzip  on;
   #tomcat集群,这里只有一台机器,不管什么均衡策略都用不到 upstream tomcat_cxts { ip_hash; #均衡策略 server localhost:8081 max_fails=3 fail_timeout=3s; } server { listen 80; server_name localhost; location / { root html; index index.html index.htm; } #静态图片转发配置 location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { root D:/webapps/static_resource/imgs; if (-f $request_filename) { expires 1d; break; } } #根据项目名称进行转发,如果是cxts,转发到上面定义的名字叫tomcat_cxts的upstream组 location /cxts { proxy_redirect off; proxy_set_header Upgrade $http_upgrade; #websocket配置参数 proxy_set_header Connection "upgrade"; #websocket配置参数 proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://tomcat_cxts/cxts; #英文字义:代理传递,即拿到数据传给哪个,这里的tomcat_cxts就是上面配置的upstream proxy_read_timeout 2; #websocket不需要此参数,加上去websocket会自动断开 } access_log logs/cxts.log; error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } }

  

 转发策略还可以写if条件,ng还有很多内置变量,监听地址还支持正则表达式,结合起来我觉得想怎么转都行了

 

5.监测配置是否能通过检查 nginx -t

6.nginx -s reload 重新加载配置

 

posted @ 2017-10-17 14:26  漫漫人生路总会错几步  阅读(5465)  评论(0编辑  收藏  举报