windows用nginx部署dist,用include配置分类,用alias实现
时间: 2024-06-09 13:07:10 浏览: 10
在 Windows 上部署 Nginx 并通过 include 配置分类和 alias 实现访问 dist 目录,可以按照以下步骤进行操作:
1. 下载 Nginx for Windows,解压后将文件夹重命名为 nginx。
2. 在 nginx/conf 目录下新建一个名为 sites 的文件夹,用于存放站点配置文件。
3. 在 sites 文件夹中新建一个名为 default.conf 的文件,并在该文件中添加以下内容:
```
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
location /dist/ {
alias html/dist/;
}
}
```
以上配置中,我们将默认站点的根目录设置为 html,将 index.html 和 index.htm 作为默认的首页文件。同时,通过 location /dist/ 配置,将访问 /dist/ 目录的请求映射到 html/dist/ 目录下。
4. 在 nginx/conf/nginx.conf 文件中添加以下内容,用于引入 sites 文件夹中的站点配置文件:
```
http {
...
include sites/*.conf;
}
```
5. 将 Vue 项目的编译结果 dist 目录复制到 nginx/html 目录下。
6. 启动 Nginx,打开浏览器,访问 http://localhost/dist/,即可访问 Vue 项目的编译结果。
这样就可以通过 Nginx 部署 Vue 项目,并通过 include 配置分类和 alias 实现访问 dist 目录了。