当前位置:网站首页>pm2之静态文件服务
pm2之静态文件服务
2022-08-10 14:31:00 【choukin】
尊重个体生存体验,对接独立思维能力,打通知识和能力之间的边界 ———— 《我的二本学生》
通过 http 协议提供静态文件服务
PM2 可以通过命令 pm2 serve 开启静态文件服务功能。它支持指定文件夹中提供的多个原始文件的访问,或者作为单页面应用。
CLI
使用简单的命令,通过http来为静态文件提供服务(就像一个前端应用)
pm2 serve <path> <port>
默认端口是8080 如果没有指定<path> 就会使用当前文件夹。也可像其他应用一样使用--name 或者 --watch
单页面应用:所有请求都重定向到 index.html
使用--spa选项把所有的请求重定向到 index.html
pm2 serve --spa
使用配置文件
// ecosystem.config.js
module.exports = {
apps : [{
script:"serve",
env:{
PM2_SERVE_PATH:'.',
PM2_SERVE_PORT:8080,
PM2_SERVE_SPA: true,
PM2_SERVE_HOMEPAGE:'./index.html',
}
}]
}
执行下面的命令然后访问 http://localhost:8080
pm2 start ecosystem.config.js
通过使用密码来设置访问权限
要保护对公开文件的访问可以使用下面的命令
pm2 serve --basic-auth-username <username> --basic-auth-password <password>
配置文件方式
// ecosystem.config.js
module.exports = {
script:"serve",
env:{
PM2_SERVE_PATH:'.',
PM2_SERVE_PORT:8080,
PM2_SERVE_SPA:'./index.html',
PM2_SERVE_BASIC_AUTH: 'true',
PM2_SERVE_BASIC_AUTH_USERNAME: 'example-login',
PM2_SERVE_BASIC_AUTH_PASSWORD: 'example-password'
}
}
边栏推荐
猜你喜欢

阿里五位MySQL封神大佬耗17个月总结出53章性能优化法则

统信 UOS V20 专业版(1050update2)发布:文件共享、全局搜索等优化

1W word detailed thread local storage ThreadLocal

机器学习总结(一)

字节终面:CPU 是如何读写内存的?

借数据智能,亚马逊云科技助力企业打造品牌内生增长力

产品使用说明书小程序开发制作说明

Do not access Object.prototype method ‘hasOwnProperty‘ from target object....

Analysys and the Alliance of Small and Medium Banks jointly released the Hainan Digital Economy Index, so stay tuned!

如何完成新媒体产品策划?
随机推荐
Epoll learn to think: a high performance server processing framework
PAT甲级 1014 排队等候(队列大模拟+格式化时间)
产品使用说明书小程序开发制作说明
Do not access Object.prototype method ‘hasOwnProperty‘ from target object....
作业
MySQL interview questions
简单的写一个防抖跟节流
面试面到了一个腾讯30k出来的,有见识到何为精通MySQL调优
Second half of 2011 System Architect Afternoon Paper II
laravel throws the error to Dingding
池化技术有多牛?来,告诉你阿里的Druid为啥如此牛逼!
Lithium battery technology
使用Uiautomator2进行APP自动化测试
laravel 抛错给钉钉
关于已拦截跨源请求CORS 头缺少 ‘Access-Control-Allow-Origin‘问题解决
C#实现访问OPC UA服务器
中学数学建模书籍及相关的视频等(2022.08.09)
镜像瘦身:每一层都不能放过
[JS Advanced] Creating sub-objects and replacing this_10 in ES5 standard specification
Classifying irises using decision trees