nginx ssi + ngx_pagespeed 实现micro frontends 开发
nginx 的ssi 功能让我们可以将不同的拼接起来,ngx_pagespeed 是pagespeed 的nginx 模块,可以帮助
我们解决前端的一些性能优化的问题,通过简单的配置就可以搞定
一张参考图

说明: demo 只简单使用了nginx ssi + ngx_pagespeed,ngx_srcache 暂时还没用
环境准备
- docker-compose file
version: "3"
services:
main:
build: ./
ports:
- "8080:80"
web1:
build:
context: ./web1
ports:
- "8180:80"
web2:
build:
context: ./web2
ports:
- "8181:80"
- 说明
main 是nginx ssi 的server ,web1 web2, 是两个不同的website,使用main 进行拼接,同时web1,web2 都是
通过main proxy 的,放到这边我们同时可以做一些cache 的优化,而且可以将服务隔离 - main dockerfile && config
# FROM openresty/openresty:alpine-fat
FROM pagespeed/nginx-pagespeed
# COPY nginx.conf usr/local/openresty/nginx/conf/
# ADD index.html /usr/local/openresty/nginx/html/index.html
# ADD index.css /usr/local/openresty/nginx/html/index.css
RUN mkdir -p /var/ngx_pagespeed_cache
COPY nginx.conf /etc/nginx/
ADD index.html /usr/share/nginx/html/index.html
ADD index.css /usr/share/nginx/html/index.css
EXPOSE 80
main nginx conf
proxy+ pagespeed
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
root /usr/share/nginx/html;
pagespeed on;
pagespeed FileCachePath /var/ngx_pagespeed_cache;
pagespeed EnableFilters combine_css;
pagespeed EnableFilters collapse_whitespace;
pagespeed EnableFilters combine_javascript;
pagespeed EnableFilters combine_heads;
pagespeed EnableFilters convert_to_webp_lossless;
pagespeed StatisticsPath /ngx_pagespeed_statistics;
pagespeed GlobalStatisticsPath /ngx_pagespeed_global_statistics;
pagespeed MessagesPath /ngx_pagespeed_message;
pagespeed ConsolePath /pagespeed_console;
pagespeed AdminPath /pagespeed_admin;
pagespeed GlobalAdminPath /pagespeed_global_admin;
gzip on;
server {
listen 80;
server_name localhost;
charset utf-8;
default_type text/html;
location /ngx_pagespeed_statistics {
}
location /ngx_pagespeed_global_statistics {
}
location /ngx_pagespeed_message {
}
location /pagespeed_console {
}
location ~ ^/pagespeed_admin {
}
location ~ ^/pagespeed_global_admin {
}
location / {
ssi on;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location /web2/ {
rewrite ^/web2(.*) $1 break;
proxy_ignore_client_abort on;
client_body_buffer_size 10M;
client_max_body_size 10G;
proxy_buffers 1024 4k;
proxy_read_timeout 300;
proxy_pass http://web2;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $remote_addr;
}
location /web1 {
rewrite ^/web1(.*) $1 break;
proxy_ignore_client_abort on;
client_body_buffer_size 10M;
client_max_body_size 10G;
proxy_buffers 1024 4k;
proxy_read_timeout 300;
proxy_pass http://web1;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $remote_addr;
}
}
}
main index page
ssi include
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>main page</title>
<link rel="stylesheet" href="index.css">
</head>
<body>
main page
<!--#include virtual="/web1/" -->
<!--#include virtual="/web2/" -->
</body>
</html>
- web1 dockerfile && config
# FROM openresty/openresty:alpine-fat
FROM pagespeed/nginx-pagespeed
# COPY nginx.conf usr/local/openresty/nginx/conf/
# ADD index.html /usr/local/openresty/nginx/html/web1/index.html
# ADD index.css /usr/local/openresty/nginx/html/web1/index.css
RUN mkdir -p /var/ngx_pagespeed_cache
COPY nginx.conf /etc/nginx/
ADD index.html /usr/share/nginx/html/index.html
ADD index.css /usr/share/nginx/html/index.css
ADD app.png /usr/share/nginx/html/app.png
EXPOSE 80
web1 nginx conf:
static website + pagespeed
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
root /usr/share/nginx/html;
pagespeed on;
pagespeed FileCachePath /var/ngx_pagespeed_cache;
pagespeed EnableFilters combine_css;
pagespeed EnableFilters collapse_whitespace;
pagespeed EnableFilters combine_javascript;
pagespeed EnableFilters combine_heads;
pagespeed EnableFilters convert_to_webp_lossless;
gzip on;
server {
listen 80;
server_name localhost;
charset utf-8;
default_type text/html;
location / {
index index.html index.html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
web1 index page
<head>
<link rel="stylesheet" href="web1/index.css">
</head>
<div id="website1">website1</div>
<img id ="logoinfo" src="web1/app.png" >
- web2 ,同web1 类似,主要是页面布局,以及引用的资源不一样
启动&&测试
- 启动
docker-compose build
docker-compose up -d
- 效果


参考资料
https://github.com/rongfengliang/nginx-ssi-pagespeed
https://www.slideshare.net/ArifWider/a-highperformance-solution-to-microservice-ui-composition-xconf-hamburg
nginx ssi + ngx_pagespeed 实现micro frontends 开发的更多相关文章
- 几个方便进行micro frontend 开发的工具&&类库
nodejs 类库 从当前来说nodejs 的npm 偏多,因为毕竟面向的是web 编程 tailor 一个layout 服务(基于fragment 的开发方式)https://github.com/ ...
- nginx ssi 配置小细节(一)
最近工作需要使用nginx的ssi (server side include)技术,在这里,将使用中的一点心得分享一下,也是一种备忘! 首先,nginx的ssi启用很简单,就只有三个最基本的指令: s ...
- Nginx - SSI Module
SSI, for Server Side Includes, is actually a sort of server-side programming language interpreted by ...
- Nginx+Python+uwsgi+Django的web开发环境安装及配置
Nginx+Python+uwsgi+Django的web开发环境安装及配置 nginx安装 nginx的安装这里就略过了... python安装 通常系统已经自带了,这里也略过 uwsgi安装 官网 ...
- Micro Frontends
Micro Frontends - extending the microservice idea to frontend development https://micro-frontends.or ...
- Micro Frontends 微前端
Micro Frontends https://martinfowler.com/articles/micro-frontends.html Integration approaches Server ...
- Micro Frontends & microservices
Micro Frontends & microservices https://micro-frontends.org/ https://github.com/neuland/micro-fr ...
- nginx ssi 模块
在nginx下与SSI配置相关的参数主要有ssi ssi_sclient_error ssi_types三个.具体的用法如下 ssi on 开启ssi支持,默认是off ssi_silent_err ...
- 使用Nginx SSI功能辅助HTML页面设计
SSI,Server Side Include,支持html静态文件内以 <!--#include file="/layout/header.html"--> 的方式 ...
随机推荐
- Integer与int的区别(转)
如果面试官问Integer与int的区别:估计大多数人只会说道两点,Ingeter是int的包装类,int的初值为0,Ingeter的初值为null.但是如果面试官再问一下Integer i = 1; ...
- 第二节 java流程控制(判断结构+选择结构)
Java的判断结构: 1.if(条件表达式){ 执行语句 }: 2.if(条件表达式){ 执行语句 }else{ 执行语句 } 3. if(条件表达式){ 执行语句 }else if(条件表达式){ ...
- activemq spring 集成与测试
1.下载安装activemq 2.pom依赖配置 3.spring配置 4.生产消息,消费消息(同步消费),监听消息(异步消费) 4.测试 5.参考博客 http://www.cnblogs.com/ ...
- TCCSuperPlayerView让Delphi支持app视频播放!
今天ChinaCock发布了新版,完美支持视频播放!新版本中,发布了新的控件TCCSuperPlayerView,以支持视频播放. 这是一个可视控件,拖放到Form上,调整好大小与位置,就可以调用他的 ...
- 微软Power BI 每月功能更新系列——3月Power BI 新功能学习
本月对Power BI Desktop 来讲是非常令人兴奋的一个月!!!以下是3月份最新的功能,下面马上带领大家看看本月的更新内容. 报表功能 报告页面工具提示(预览) 通过报告页面工具提示功能,可 ...
- jQuery的事件
事件冒泡处理 使用event.stopPropagation();阻止事件冒泡 冒泡事件也可以使用return false来处理 并且 <script type="text/javas ...
- 百练6247-过滤多余的空格-2015正式B题
B:过滤多余的空格 总时间限制: 1000ms 内存限制: 65536kB 描述 一个句子中也许有多个连续空格,过滤掉多余的空格,只留下一个空格. 输入 一行,一个字符串(长度不超过200),句子的 ...
- 字符串(text)格式的html代码文本转为DOM对象
/*字符串转dom对象*/ window.strimgTurnDom = function(txt) { try //Internet Explorer { xmlDoc=new ActiveXObj ...
- sql数据查询基础笔记
使用SELETE语句进行查询 语法 SELECT<列名> FROM<表名> [ORDER BY <排序的列名>[ASC或DESC]] 1.查询所有的数据和列 SE ...
- GitHub使用教程、注册与安装
GitHub注册与安装 本文提供全流程,中文翻译.Chinar坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 -- 高分辨率用户请调整网页缩放比例至200%) 1 进入GitHub官网:http ...