title: Dockerized Angular - Nginx try_files does break with hard refresh
body: <p>We are running a multi-language Angular app using the node-alpine image as base. Our application builds for once for each language and all build are packed into the same image. Routing between the images is done with an Nginx server in the image and language-specific baseHrefs.</p>
  <p>We are also using Angular routing and I have now the following problem to fix:<br />
  If a user refreshes the page using &quot;F5&quot; everything works.<br />
  If the user refreshes with &quot;Ctrl-Shift-R&quot; the application breaks.<br />
  Both refreshes should work.</p>
  <p>This is our folder structure in the image:</p>
  <pre><code>
      /usr/share/nginx/html/  
      |-en/mobile-ng/index.html  
      |-de/mobile-ng/index.html  
      |-fr/mobile-ng/index.html  
      |-it/mobile-ng/index.html  
  
  </code></pre>
  <p>The nginx config looks like this:</p>
  <pre><code>
      server {
          listen       80;
          listen  [::]:80;
          server_name  localhost;
      
          location / {
              root   /usr/share/nginx/html;
              index  index.html index.htm;
              try_files $uri $uri/ /index.html;
          }
      
          # redirect server error pages to the static page /50x.html
          #
          error_page   500 502 503 504  /50x.html;
          location = /50x.html {
              root   /usr/share/nginx/html;
          }
      
      }
  
  </code></pre>
  <p>If the user is at &quot;host/en/mobile-ng/login&quot; and refreshed as described above, the page breaks with a HTTP 500 Error.</p>
  <p>I've already tried changing the try_files directive to
  <code>try_files $uri $uri/ index.html;</code>
  which did not work. I also tried to rewrite the URL, but I am not experienced enough to pull this off.</p>
  <p>If someone would have an idea, what I could try next, that would be awesome.</p>
  <p>EDIT:</p>
  <p>Log output when the page is refreshed with <code>try_files $uri $uri/ /index.html;</code>:</p>
  <pre><code>172.17.0.1 - - [27/Apr/2022:10:53:27 +0000] &quot;GET /en/mobile-ng/assets/data/appConfig.json HTTP/1.1&quot; 304 0 &quot;http://localhost/en/mobile-ng/&quot; &quot;Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36&quot; &quot;-&quot;
  172.17.0.1 - - [27/Apr/2022:10:53:27 +0000] &quot;GET /en/mobile-ng/assets/logos/logo_white_transparent.png HTTP/1.1&quot; 304 0 &quot;http://localhost/en/mobile-ng/&quot; &quot;Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36&quot; &quot;-&quot;
  172.17.0.1 - - [27/Apr/2022:10:53:27 +0000] &quot;GET /en/mobile-ng/assets/logos/logoSlogan.png HTTP/1.1&quot; 304 0 &quot;http://localhost/en/mobile-ng/login&quot; &quot;Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36&quot; &quot;-&quot;
  172.17.0.1 - - [27/Apr/2022:10:53:27 +0000] &quot;GET /en/mobile-ng/assets/icons/icon-144x144.png HTTP/1.1&quot; 304 0 &quot;http://localhost/en/mobile-ng/login&quot; &quot;Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36&quot; &quot;-&quot;
  172.17.0.1 - - [27/Apr/2022:10:53:29 +0000] &quot;GET /en/mobile-ng/ngsw-worker.js HTTP/1.1&quot; 304 0 &quot;http://localhost/en/mobile-ng/ngsw-worker.js&quot; &quot;Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36&quot; &quot;-&quot;
  2022/04/27 10:53:32 [notice] 1#1: signal 28 (SIGWINCH) received
  2022/04/27 10:53:32 [notice] 1#1: signal 28 (SIGWINCH) received
  172.17.0.1 - - [27/Apr/2022:10:53:32 +0000] &quot;GET /en/mobile-ng/ngsw.json?ngsw-cache-bust=0.4949552840036362 HTTP/1.1&quot; 200 6037 &quot;http://localhost/en/mobile-ng/ngsw-worker.js&quot; &quot;Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36&quot; &quot;-&quot;
  172.17.0.1 - - [27/Apr/2022:10:53:32 +0000] &quot;GET /en/mobile-ng/ngsw.json?ngsw-cache-bust=0.8663667049611969 HTTP/1.1&quot; 200 6037 &quot;http://localhost/en/mobile-ng/ngsw-worker.js&quot; &quot;Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36&quot; &quot;-&quot;
  2022/04/27 10:53:32 [notice] 1#1: signal 28 (SIGWINCH) received
  2022/04/27 10:53:33 [notice] 1#1: signal 28 (SIGWINCH) received
  2022/04/27 10:53:33 [notice] 1#1: signal 28 (SIGWINCH) received
  2022/04/27 10:53:33 [notice] 1#1: signal 28 (SIGWINCH) received
  2022/04/27 10:53:34 [notice] 1#1: signal 28 (SIGWINCH) received
  2022/04/27 10:53:35 [notice] 1#1: signal 28 (SIGWINCH) received
  2022/04/27 10:53:35 [notice] 1#1: signal 28 (SIGWINCH) received
  2022/04/27 10:53:36 [error] 25#25: *2 rewrite or internal redirection cycle while internally redirecting to &quot;/index.html&quot;, client: 172.17.0.1, server: localhost, request: &quot;GET /en/mobile-ng/login HTTP/1.1&quot;, host: &quot;localhost&quot;
  172.17.0.1 - - [27/Apr/2022:10:53:36 +0000] &quot;GET /en/mobile-ng/login HTTP/1.1&quot; 500 579 &quot;-&quot; &quot;Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36&quot; &quot;-&quot;
  2022/04/27 10:53:36 [notice] 1#1: signal 28 (SIGWINCH) received
  2022/04/27 10:53:36 [error] 24#24: *1 rewrite or internal redirection cycle while internally redirecting to &quot;/index.html&quot;, client: 172.17.0.1, server: localhost, request: &quot;GET /favicon.ico HTTP/1.1&quot;, host: &quot;localhost&quot;, referrer: &quot;http://localhost/en/mobile-ng/login&quot;
  172.17.0.1 - - [27/Apr/2022:10:53:36 +0000] &quot;GET /favicon.ico HTTP/1.1&quot; 500 579 &quot;http://localhost/en/mobile-ng/login&quot; &quot;Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36&quot; &quot;-&quot;
  </code></pre>
  <p>Log output with <code>try_files $uri $uri/ index.html;</code>:</p>
  <pre><code>172.17.0.1 - - [27/Apr/2022:11:05:19 +0000] &quot;GET /en/mobile-ng/assets/data/appConfig.json HTTP/1.1&quot; 200 664 &quot;http://localhost/en/mobile-ng/&quot; &quot;Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36&quot; &quot;-&quot;
  172.17.0.1 - - [27/Apr/2022:11:05:19 +0000] &quot;GET /en/mobile-ng/assets/logos/logo_white_transparent.png HTTP/1.1&quot; 200 3478 &quot;http://localhost/en/mobile-ng/&quot; &quot;Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36&quot; &quot;-&quot;
  172.17.0.1 - - [27/Apr/2022:11:05:19 +0000] &quot;GET /en/mobile-ng/assets/logos/logoSlogan.png HTTP/1.1&quot; 200 6487 &quot;http://localhost/en/mobile-ng/login&quot; &quot;Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36&quot; &quot;-&quot;
  172.17.0.1 - - [27/Apr/2022:11:05:19 +0000] &quot;GET /en/mobile-ng/assets/logos/favicon.ico HTTP/1.1&quot; 200 39833 &quot;http://localhost/en/mobile-ng/login&quot; &quot;Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36&quot; &quot;-&quot;
  172.17.0.1 - - [27/Apr/2022:11:05:19 +0000] &quot;GET /en/mobile-ng/assets/icons/icon-144x144.png HTTP/1.1&quot; 200 3973 &quot;http://localhost/en/mobile-ng/login&quot; &quot;Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36&quot; &quot;-&quot;
  172.17.0.1 - - [27/Apr/2022:11:05:19 +0000] &quot;GET /en/mobile-ng/ngsw-worker.js HTTP/1.1&quot; 200 144457 &quot;http://localhost/en/mobile-ng/ngsw-worker.js&quot; &quot;Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36&quot; &quot;-&quot;
  172.17.0.1 - - [27/Apr/2022:11:05:21 +0000] &quot;GET /en/mobile-ng/ngsw-worker.js HTTP/1.1&quot; 304 0 &quot;http://localhost/en/mobile-ng/ngsw-worker.js&quot; &quot;Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36&quot; &quot;-&quot;
  172.17.0.1 - - [27/Apr/2022:11:05:21 +0000] &quot;GET /en/mobile-ng/login HTTP/1.1&quot; 404 555 &quot;-&quot; &quot;Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36&quot; &quot;-&quot;
  2022/04/27 11:05:21 [error] 26#26: *2 open() &quot;/etc/nginx/htmlindex.html&quot; failed (2: No such file or directory), client: 172.17.0.1, server: localhost, request: &quot;GET /en/mobile-ng/login HTTP/1.1&quot;, host: &quot;localhost&quot;
  2022/04/27 11:05:21 [error] 26#26: *2 open() &quot;/etc/nginx/htmlindex.html&quot; failed (2: No such file or directory), client: 172.17.0.1, server: localhost, request: &quot;GET /favicon.ico HTTP/1.1&quot;, host: &quot;localhost&quot;, referrer: &quot;http://localhost/en/mobile-ng/login&quot;
  172.17.0.1 - - [27/Apr/2022:11:05:21 +0000] &quot;GET /favicon.ico HTTP/1.1&quot; 404 555 &quot;http://localhost/en/mobile-ng/login&quot; &quot;Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36&quot; &quot;-&quot;
  172.17.0.1 - - [27/Apr/2022:11:05:24 +0000] &quot;GET /en/mobile-ng/ngsw.json?ngsw-cache-bust=0.7653982328060656 HTTP/1.1&quot; 200 6037 &quot;http://localhost/en/mobile-ng/ngsw-worker.js&quot; &quot;Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36&quot; &quot;-&quot;
  172.17.0.1 - - [27/Apr/2022:11:05:25 +0000] &quot;GET /en/mobile-ng/ngsw.json?ngsw-cache-bust=0.9716895517160795 HTTP/1.1&quot; 200 6037 &quot;http://localhost/en/mobile-ng/ngsw-worker.js&quot; &quot;Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36&quot; &quot;-&quot;
  
  </code></pre>