Nginx (engine x) 是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP服务器。是一种轻量级的Web服务器,可以作为独立的服务器部署网站。它高性能和低消耗内存的结构受到很多大公司青睐,如淘宝网站架设。。
windows系统
1 安装
http://nginx.org/en/download.html
2 下载后解压,注意:名称不能有中文
3 在上图的页面。打开控制台,输入指令开启,然后在浏览器页面输入localhost
默认端口为80.可省略不写,出现上图代表开启成功
nginx的指令介绍
start nginx | 开启nginx服务 |
nginx.exe -s stop | 关闭nginx服务,快速停止nginx,可能并不保存相关信息 |
nginx.exe -s quit | 关闭nginx服务,完整有序的停止nginx,并保存相关信息 |
nginx.exe -s reload | 重载nginx服务,当你改变了nginx配置信息并需要重新载入这些配置 |
taskkill /F /IM nginx.exe > nul | 强关nginx服务器 |
hash模式下的开启
1 将打包后的dist文件放入nginx的html文件夹里
2 浏览器输入localhost/dist/index.html开启
history模式下的开启
1 vue项目开启history模式(默认hash)并打包
在vue项目中的router的index.js中设置
const router = new VueRouter({
mode:'history',
routes
});
2 在nginx文件夹中的conf的nginx.conf里设置
location / {
try_files $uri $uri/ /dist/index.html;
}
这里的dist是文件夹名,可以更改