milroyfraser's avatar

nginx redirect all requests to index.html

Hi All, I'm working on Vuejs SPA + Lalavel API + Laradock latest. I'm trying to setup domain for SPA myapp.dev also I need to change nginx config according to https://router.vuejs.org/en/essentials/history-mode.html in order to fix routing issue. I have added site config to nginx\sites\myapp.conf and its content is

server {

    listen 80;
    listen [::]:80;

    server_name myapp.dev;
    root /var/www/app/dist;
    index index.html;

    location / {
         try_files $uri $uri/ /index.html;
    }
}

What is wrong here? it doesn't seems to be working :(

@bashy please help me with this ;)

0 likes
4 replies
bmconcepts's avatar

Did you give it a Symlink in the /etc/nginx/sites-enabled?

ln -s /etc/nginx/sites-available/myapp.dev /etc/nginx/sites-enabled/myapp.dev

restart nginx

Greetings

Marco

milroyfraser's avatar

Tnx @bmconcepts myapp.dev is working. You can navigate through the application by clicking links so it uses vue-router, but when you refresh or directly type a url in the address bar e.g. myapp.dev/another-url it will show you nginx 404. Instead of doing that nginx needs to redirect all the requests to index.html as explained in https://router.vuejs.org/en/essentials/history-mode.html look under nginx. Tnx again!

jlrdw's avatar

Look at the example Nginx config from the laravel documentation.

Please or to participate in this conversation.