Explanation

Since many applications to achieve a rate letter separated front and rear ends, i.e., the interface layer and the business logic separated.
Business logic layer applications need to use tomcat, jar, etc. run, static pages using nginx proxy access.

Nginx and configurable cache access large static resources (e.g., a user avatar), to improve the response speed of the system.

installation

Deploy the following link

- Agent software nginx deployment

 

Acting static resources
- Configure proxy static resources
# 将静态资源放于/data/eim/www目录下
ll /data/eim/www/plist/eim.plist

# nginx配置代理/data/eim/www目录下的静态资源 vim /etc/nginx/conf.d/default.conf # 配置运行端口 listen 80; # 静态页面路径,将文件放于该目录下,即可被浏览器访问 location / { root /data/eim/www; # 错误页面路径 location = /50x.html { root /data/eim/www; :wq!
- haproxy agent
        acl nginx-server path_beg -i /plist
        use_backend nginx-server if nginx-server

backend nginx-server
        mode http
        option forwardfor
        server wget 10.10.10.100:80 check inter 10s

Browser to access static resources http://haproxy_ip:port/plist/eim.plist
 

Cache user avatar
- nginx proxy service configuration file preview

edit/etc/nginx/conf.d/default.conf

worker_processes  4;

events {
    worker_connections  4096; use epoll; } http { upstream cloudfs-server { # cloudfs地址 server 10.111.12.34:8082 max_fails=3 fail_timeout=30s; server 10.111.34.44:8082 max_fails=3 fail_timeout=30s; } # 需要提前创建缓存文件存放的目录/data/eim/nginx_cloudfs_image_cache,可使用的空间至少比配置的max_size=30g 大 proxy_cache_path /data/eim/nginx_cloudfs_image_cache levels=1:2 keys_zone=cloudfs_image_cache:200m max_size=30g inactive=15d; # 如果有强制升级客户端,造成并发下载客户端压力过大可按如下配置缓存客户端文件 # proxy_cache_path /data/eim/nginx_upgrade_cache levels=1:2 keys_zone=upgrade_cache:100m max_size=10g inactive=30d; rewrite_log on; server { listen 8088; server_tokens off; # 缓存文件 location ~ ^(/api/fs/view/|/cloudfs/api/fs/view/) { if ($uri ~* /api/fs/view/) { rewrite ^/api/fs/view/(.*)$ /cloudfs/api/fs/view/$1 break; } proxy_cache cloudfs_image_cache; proxy_cache_valid 200 15d; # 缓存404 proxy_cache_valid 404 1d; proxy_cache_key $uri$args; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $host; add_header Nginx-Cache $upstream_cache_status; proxy_pass http://cloudfs-server; break; } # 缓存升级客户端文件 # location ~ ^/upgrade/api/fs/download/internal/ { # # rewrite ^/upgrade/api/fs/download/internal/(.*)$ /cloudfs/api/fs/download/internal/$1 break; # # proxy_cache upgrade_cache; # proxy_cache_valid 200 30d; # proxy_cache_key $uri$args; # proxy_set_header X-Real-IP $remote_addr; # proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; # proxy_set_header Host $host; # add_header Nginx-Cache $upstream_cache_status; # proxy_pass http://cloudfs-server; # break; # } } }
- haproxy forwards the relevant path to the nginx proxy
# 此段配置需要在cloudfs的acl之前
acl nginx-server path_beg -i /api/fs/view/ /cloudfs/api/fs/view/ # 缓存客户端文件 # acl nginx-server path_beg -i /upgrade/api/fs/download/internal/ use_backend nginx-server if nginx-server backend nginx-server mode http option forwardfor # 通过访问某个文件做健康检查,如某个应用的图标 option httpchk GET /cloudfs/api/fs/view/Z3JvdXAyL00wMC8wMy81RC9Dc0tzTEZZZmNKS0ljRTZ5QUFBR3R0X3MzU2dBQUI2cVFQXzNIa0FBQWJPNjIwOTI2Ng== server nginx-247 127.0.0.1:8088 weight 1 check inter 10s server nginx-248 10.100.100.8:8088 weight 2 check inter 10s