刚刚前端将vue项目的路由模式由hash变成了history,刷新项目页面出现404,在官方提供的vue-router文档中讲解了怎么解决这个问题,并且给了配置例子【官方文档】。
修改项目域名的Nginx站点conf文件配置,添加下面代码就可以了【修改完配置记得重启下Nginx】
location / {
try_files $uri $uri/ /index.html;
}
下面是完整的conf文件样子
server
{
listen 80;
listen 443 ssl http2;
server_name www.test.net test.net;
index index.php index.html index.htm default.php default.htm default.html;
root /www/wwwroot/test;
if ($server_port !~ 443){
rewrite ^(/.*)$ https://$host$1 permanent;
}
ssl_certificate /www/server/panel/vhost/cert/www.test.net/fullchain.pem;
ssl_certificate_key /www/server/panel/vhost/cert/www.test.net/privkey.pem;
ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
error_page 497 https://$host$request_uri;
include enable-php-74.conf;
location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md)
{
return 404;
}
location ~ \.well-known{
allow all;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
error_log off;
access_log /dev/null;
}
location ~ .*\.(js|css)?$
{
expires 12h;
error_log off;
access_log /dev/null;
}
location / {
try_files $uri $uri/ /index.html;
}
}
|