当前位置:网站首页>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'
}
}
边栏推荐
猜你喜欢
随机推荐
1W字详解线程本地存储 ThreadLocal
第五讲 测试技术与用例设计
Do not access Object.prototype method ‘hasOwnProperty‘ from target object....
数学建模学习视频及资料集(2022.08.10)
写不完的数学试卷-----试卷生成器(Qt含源码)
领域驱动模型设计与微服务架构落地-从项目去剖析领域驱动
八大排序总是忘?快来这里~
leetcode 739. Daily Temperatures 每日温度(中等)
@RequestBody的使用[通俗易懂]
借数据智能,亚马逊云科技助力企业打造品牌内生增长力
学习MySQL 临时表
How is the monthly salary table stored in the database?Ask for a design idea
锂电池技术
这一次,话筒给你:向自由软件之父斯托曼 提问啦!
Open source SPL wipes out tens of thousands of database intermediate tables
符合信创要求的堡垒机有哪些?支持哪些系统?
作业
The a-modal in the antd component is set to a fixed height, and the content is scrolled and displayed
AWS Security Fundamentals
1004 (tree array + offline operation + discretization)