When deploying the Vue project on the nginx server on Linux, you can only access the home page and other pages 404

Alibaba cloud Q & A 2022-02-13 07:34:28 阅读数:590

deploying vue project nginx server

For local use npm run build Command to package the project , Then compress the packaged project dist.zip The file is uploaded to the server , Unzip in /usr/local/nginx/( New creation )root/data Next .( Just change this to ./ 了 , And below build The in has also been modified ./)

image.png

stay nginx.config Configuration file modification . image.png

After the start nginx The server , Can pass ip/ Redirect to ip/blogs page .

image.png

But the report is wrong , Not deployed locally nginx The server , direct npm run dev When it's running , It can be displayed normally , No error reported .

Click login Button , Jump to ip/login But report 404

image.png

Other paths can't find the page , Don't know what's going on .

Some routing configurations

image.png




Take the answer 1:

Hello! , To set access, all paths return index.html stay nginx In the configuration file ,index Add after instruction try_files Can solve

try_files $uri $uri/ /index.html;

copyright:author[Alibaba cloud Q & A],Please bring the original link to reprint, thank you. https://en.javamana.com/2022/02/202202130734261375.html