当前位置:网站首页>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'
}
}
边栏推荐
- 2022年网络安全培训火了,缺口达95%,揭开网络安全岗位神秘面纱
- systemui屏蔽通知栏
- How is the monthly salary table stored in the database?Ask for a design idea
- 兆骑科创创业赛事活动发布平台,创业赛事,项目路演
- 容器化 | 在 S3 实现定时备份
- 字节终面:CPU 是如何读写内存的?
- mysql进阶(三十三)MySQL数据表添加字段
- laravel throws the error to Dingding
- The a-modal in the antd component is set to a fixed height, and the content is scrolled and displayed
- How does vue clear the tab switching cache problem?
猜你喜欢
E. Cross Swapping(并查集变形/好题)
DB2查询2个时间段之间的所有月份,DB2查询2个时间段之间的所有日期
蓝帽杯半决赛火炬木wp
1W word detailed thread local storage ThreadLocal
[Gazebo Introductory Tutorial] Lecture 3 Static/Dynamic Programming Modeling of SDF Files
1W字详解线程本地存储 ThreadLocal
什么?你还不会JVM调优?
使用mysq语句操作数据库
Classifying irises using decision trees
中学数学建模书籍及相关的视频等(2022.08.09)
随机推荐
2011年下半年 系统架构设计师 下午试卷 II
2022-08-10 Daily: Swin Transformer author Cao Yue joins Zhiyuan to carry out research on basic vision models
PyTorch 多机多卡训练:DDP 实战与技巧
AWS Security Fundamentals
使用决策树对鸢尾花进行分类
舵机内部结及工作原理浅析[通俗易懂]
波士顿房价预测
符合信创要求的堡垒机有哪些?支持哪些系统?
中学数学建模书籍及相关的视频等(2022.08.09)
物资采购小程序开发制作功能介绍
Error: Rule can only have one resource source (provided resource and test + include + exclude)
leetcode 739. Daily Temperatures 每日温度(中等)
第五讲 测试技术与用例设计
Flask框架——MongoEngine使用MongoDB数据库
力扣解法汇总640-求解方程
线上线下课程教学培训小程序开发制作功能介绍
Azure IoT 合作伙伴技术赋能工作坊:IoT Dev Hack
[JS Advanced] Creating sub-objects and replacing this_10 in ES5 standard specification
$‘\r‘: command not found
王学岗—————————哔哩哔哩直播-手写哔哩哔哩硬编码录屏推流(硬编)(26节课)