但是访问静态文件时出现404
时间: 2023-10-23 14:28:21 浏览: 39
好的,如果静态文件访问出现了404错误,可以尝试添加`location`指令来指定访问静态资源的路径,例如:
```
http {
server {
listen 80;
server_name yourdomain.com;
root /home/app/nginx;
location /entwechat {
alias /home/app/nginx/EntWechat/dist;
try_files $uri $uri/ /entwechat/index.html;
}
location /h5 {
alias /home/app/nginx/H5/dist;
try_files $uri $uri/ /h5/index.html;
}
# 指定静态资源路径
location /static {
alias /home/app/nginx/static;
}
location / {
alias /home/app/nginx/conf/nginx.conf;
}
}
}
```
在这个配置文件中,添加了`location /static`指令,用来指定静态资源的访问路径。同时,需要将静态资源文件放置在`/home/app/nginx/static`目录下,这样就可以正常访问静态资源了。
相关推荐
![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)