Nginx怎么设置才能把URL映射到React的路由上
发布于 6 年前 作者 jiyarong 3113 次浏览 来自 问答
server {
        listen       80;
        server_name  blog.peterji.cn;
        location / {
            alias /var/www/peter-blog-app/build/;
        }
}

现在能打开的只有首页,其他只能靠点链接,直接打url会404

4 回复

应该是需要设置入口文件吧,vue的history模式是这样的

来自酷炫的 CNodeMD

server {
        listen       80;
        server_name  blog.peterji.cn;
location / {
    add_header Cache-Control "no-cache, no-store";
    root    /root/html/dist;
    index    index.html index.htm;
    try_files $uri $uri/ /index.html;
}

server { listen 80; server_name localhost; location / { root /www/cms/build; index index.html; } location /api { #反向代理解决跨域 proxy_pass http://XXXXXXXX; } } 这是我的

多谢各位!解决了

回到顶部