2

I'm tinkering with Docker and NGINX and I have an angular app that is currently responding to http://localhost. When you click a link in my app, it updates the url in your browser to http://localhost/home. If you refresh the page though you get the standard nginx 404 page.

How can I modify my nginx.conf file so that http://localhost and http://localhost/home will display my angular app instead of a 404?

nginx.conf

events {}

http {

  index index.html;

  server {
    root /usr/share/nginx/html;
    location / {
       #proxy_pass /
    }
  }
}

Dockerfile

FROM nginx
COPY ./dist /usr/share/nginx/html
COPY nginx.conf /etc/nginx/nginx.conf
EXPOSE 80
  • Please show the complete configuration. – Tero Kilkanen Oct 31 '17 at 7:06
  • That is the complete configuration. – Catfish Oct 31 '17 at 15:08
  • The virtual server block is missing listen directive, and possibly server_name. – Tero Kilkanen Oct 31 '17 at 20:18
1

Seems all I needed was the try_files line.

events {}

http {

  index index.html;

  server {
    root /usr/share/nginx/html;

    location / {
       try_files $uri $uri/ /index.html;
    }
  }
}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.