How to work around the 404 error on nginx?

后端 未结 1 1167
情歌与酒
情歌与酒 2021-01-23 03:03

I have an angular 4 SPA app and I\'am using docker for production. Looks fine so far. Via terminal I go to /dist folder and from there I let docker point to the con

相关标签:
1条回答
  • 2021-01-23 03:48

    The issue is that in the default nginx config it only uses the index directive. What you need is the try_files directive which will first try the uri then it will go to the index.html

    To do this you need to pass in your own default virtual host config. Something like the following should work. This is based on Nginx's Docker Github

    server {
      listen       80;
      server_name  localhost;
      root   /usr/share/nginx/html;
      index  index.html index.htm;
    
      location / {
        try_files $uri /index.html;
      }
    }
    

    After that is it should be just making that file as a volume in the right spot.

    docker run -d -p 9090:80 -v $(pwd):/usr/share/nginx/html -v (path_to_your_config):/etc/nginx/conf.d/default.conf nginx:alpine

    0 讨论(0)
提交回复
热议问题