我自己使用的nginx版本:1.19.2
出现的问题: 输入地址第一次能进去页面,刷新当前页面直接404.
解决方案:
location / {
try_files $uri $uri/ @router;
index index.html;
}
location @router {
rewrite ^.*$ /index.html last;
}
然后附上修改后的nginx配置文件
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 端口;
server_name ip地址;
#你前端项目存放的地址
root /usr/local/nginx/html;
location / {
try_files $uri $uri/ @router;
index index.html;
}
location @router {
rewrite ^.*$ /index.html last;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}