I have a project on an Ubuntu server that produces a 404 error when refreshing or manually typing the URL. For example, I can go to example.com but I cannot go to example.com/home or refresh while on that page without getting a 404. Clicking on links work as expected. I’m using Vue router in history mode and have added the following in the http section of the nginx.conf file:
server {
listen 80;
server_name example.com;
root /var/www/example.com;
location / {
try_files $uri $uri/ /index.html;
}
}
I can test the configuration with sudo nginx -t and it passes, but I’m still getting 404 errors. It might be worth mentioning that I have multiple server blocks on this server.
2
Answers
I modified the nginx.conf a bit and this worked:
Dockerfile
nginx.conf
Build image
Run container