nginx在二级目录部署下vue文件
时间: 2024-04-22 12:24:03 浏览: 24
要在nginx中部署vue文件,可以按照以下步骤进行操作:
1. 在服务器上安装nginx,并确保已启动。可以使用以下命令安装nginx(适用于Ubuntu):
```
sudo apt update
sudo apt install nginx
```
2. 进入nginx的配置目录,一般是`/etc/nginx`,使用以下命令进入该目录:
```
cd /etc/nginx
```
3. 在该目录下创建一个新的配置文件,比如`my-vue-app.conf`:
```
sudo nano sites-available/my-vue-app.conf
```
4. 在打开的文件中,使用以下配置示例作为起点:
```nginx
server {
listen 80;
server_name your-domain.com;
root /path/to/vue-app/dist;
index index.html;
location /subdirectory {
try_files $uri $uri/ /subdirectory/index.html;
}
}
```
注意将 `your-domain.com` 替换为你的域名,`/path/to/vue-app/dist` 替换为你vue项目打包后的dist目录的路径,`/subdirectory` 替换为你想要部署的二级目录名称。
5. 保存并关闭文件(按Ctrl+X,然后输入Y并按Enter)。
6. 创建一个符号链接将新的配置文件链接到 `sites-enabled` 目录,以便Nginx加载该配置文件:
```
sudo ln -s /etc/nginx/sites-available/my-vue-app.conf /etc/nginx/sites-enabled/
```
7. 检查Nginx配置是否正确:
```
sudo nginx -t
```
如果没有错误,重启Nginx服务:
```
sudo service nginx restart
```
现在,你的vue应用程序应该已经在二级目录下成功部署了。可以通过访问 `your-domain.com/subdirectory` 来访问它。记得将 `your-domain.com` 替换为你的域名,`/subdirectory` 替换为你的二级目录名称。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)