解决vue项⽬部署后刷新404问题
我们在vue项⽬中,使⽤history模式时,部署后刷新会出现404问题,原因是,刷新时。浏览器会通过url去请求对应路径的资源⽂件,找不到时就会出现这种问题。那如何解决呢?
暗度陈仓通过修改服务器的配置⽂件,让其刷新时找不到对应⽂件时,都指向index.html,这时index.html就会根据对应路径显⽰对应路由。
酬崔驸马惠笺百张兼贻四韵以nginx服务器配置举例:
image.png
以下配置仅供参考,可根据⾃⼰实际需要进⾏调整。
#ur nobody;
worker_process 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
黄锦明worker_connections 1024;
}
http {
include pes;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_ur [$time_local] "$request" '
# '$status $body_bytes_nt "$http_referer" '
# '"$http_ur_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
ndfile on;
#tcp_nopush on;
#tcp_nopush on;
#keepalive_timeout 0;
家乡的春节习俗keepalive_timeout 65;
短信铃声怎么设置gzip on;
rver {
listen 8082;
rver_name localhost;
#chart koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
#error_page 404 /404.html;
制诰# redirect rver error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
心里减肥}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass 127.0.0.1;
#}
# pass the PHP scripts to FastCGI rver listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
滋味烤鱼#}
}
# another virtual host using mix of IP-, name-, and port-bad configuration #
#rver {
# listen 8000;
# listen somename:8080;
# rver_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS rver
#
#rver {
# listen 443 ssl;
# rver_name localhost;