如何让多个不同类型的后端网站用一个nginx进行反向代理实际场景分析
2019-11-04 00:00
1691 查看
前段时间公司根据要求需要将聚石塔上服务器从杭州整体迁移到张家口,刚好趁这次机会将这些乱七八糟的服务器做一次梳理和整合,断断续续一个月迁移完
成大概优化掉了1/3的机器,完成之后遇到了一些问题,比如曾今零零散散部署在生产上一些可视化UI:apollo,kibana,grafana,jenkins 等等要么采用80端口,要
么对公开放了其他端口,为了安全,现在不再开放非80之外的公网端口,由于机器少了,80端口不够,这些可视化UI不再能直接访问到了。所以需另寻其他出路。
一:用nginx做反向代理
为了解决这两个问题,自然第一反应想到的就是使用反向代理,我的理想构思下应该是下图这样的。
#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info 576 ; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; log_format main '$host ----> $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; server { ae4 listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; # location = /get { # set_unescape_uri $key $arg_key; # this requires ngx_set_misc # redis2_query get $key; # redis2_pass 10.105.13.174:6379; # } location / { if ($host = "a.mip.com") { proxy_pass http://localhost:8001; } if ($host = "j.mip.com") { proxy_pass http://localhost:8002; } root html; index index.html index.htm; } #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 1c3e 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 8001; server_name somename alias another.alias; location / { root html; index apollo.html; } } server { listen 8002; server_name somename alias another.alias; location / { root html; index jenkins.html; } } # 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; # } #} }View Code
相关文章推荐
- 如何对一个网站进行分析
- 同 一个页面,不同请求路径,如何根据实际场景写JS
- 如何快速实现一个基于 Nginx 网站的监控场景
- Nginx如何反向代理网站和设置虚拟主机
- 使用 Nginx 对 ASP.NETCore网站 或 Docker 等进行反向代理
- 【原创】如何分析一个网站使用的服务器类型
- 如何基于ARMS快速实现一个基于Nginx的网站监控场景 – 操作篇
- Nginx前端设置反向代理,后端Apache如何获取访客的真实IP,结合PHP
- nginx 根据网址进行不同反向代理方法
- 如何快速实现一个基于 Nginx 网站的监控场景
- Nginx如何反向代理网站和设置虚拟主机
- Nginx如何反向代理网站和设置虚拟主机
- web developer tips (60):如何对ASP.Net网站进行性能分析
- 如何进行一次全面的网站分析
- iOS开发工具-如何使用网络封包分析工具Charles,通过配置proxy对http、https、tcp、udp 等协议的请求响应过程交互信息进行分析、判断、解决我们移动开发中的遇到的各种实际问题。
- Nginx反向代理到后端的tomcat上实现动静分离
- 【大型网站技术实践】初级篇:借助Nginx搭建反向代理服务器
- nginx反向代理后端IIS持续报错504
- 如何分析一个网站?
- 烂泥:使用UPUPW的Nginx进行反向代理及反向代理IIS