当前位置:网站首页>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'
}
}
边栏推荐
猜你喜欢

使用Uiautomator2进行APP自动化测试

Alibaba的秒杀系统—千亿级并发设计手册上线了

DB2查询2个时间段之间的所有月份,DB2查询2个时间段之间的所有日期

物资采购小程序开发制作功能介绍

PyTorch multi-machine multi-card training: DDP combat and skills

注意力模型---Attention Model

易观分析联合中小银行联盟发布海南数字经济指数,敬请期待!

王学岗—————————哔哩哔哩直播-手写哔哩哔哩硬编码录屏推流(硬编)(26节课)

SQL学习(基础)

Lack of comparators, op amps come to the rescue!(Op amp is recorded as a comparator circuit)
随机推荐
等保2.0一个中心三重防护指的是什么?如何理解?
PyTorch multi-machine multi-card training: DDP combat and skills
2011年下半年 系统架构设计师 下午试卷 II
Existing in the rain of PFAS chemical poses a threat to the safety of drinking water
numpy.meshgrid()理解
How is the monthly salary table stored in the database?Ask for a design idea
PHP judges whether the file has content, and if there is no content, copy another file to write
leetcode 739. Daily Temperatures Daily Temperatures (Moderate)
[219] The training course notes of the go engineer with more than 3,000 MOOCs 02 Programming ideas in the go language
易观分析联合中小银行联盟发布海南数字经济指数,敬请期待!
WSL 提示音关闭
【MindSpore易点通机器人-02】设计与技术选型
MySQL interview questions
FPN详解
无线网络、HTTP缓存、IPv6
池化技术有多牛?来,告诉你阿里的Druid为啥如此牛逼!
安装mysql报错处理
PHP 判断文件是否有内容,没有内容则复制另一个文件写入
图式图例规范尺寸
vue 怎么清除tab 切换缓存问题 ?