title: How to serve compile assets with rails and nginx on docker?
body: <p>I've been preparing for production with my rails application and I'm having a lot of trouble with nginx. Compared to development where the assets weren't precompiled, nothing works now. I use sprockets to handle the css, images and fonts and webpacker for the javascript. Problem is, whenever I try anything in the tutorials I see, it doesn't work. I always get erors such as &quot;No route matches [GET] &quot;/packs/js/&quot; or &quot;No route matches [GET] &quot;/assets/...&quot;.</p>
  <p>Here's what my default.conf looks like :</p>
  <pre><code>upstream railsapp {
    server hubsite:3000;
  }
  
  server {
      listen 80 default_server;
      listen [::]:80 default_server;
  
      root /app/public;
  
      # Deny requests for files that should never be accessed  
      location ~ /\. {    
          deny all;  
      }
      location ~* ^.+\.(rb|log|go|exe)$ {    
          deny all;  
      }
  
      try_files $uri @rails;
  
      # serve static (compiled) assets directly if they exist (for rails production)
      location ~ ^/(assets|packs|images|javascripts|stylesheets|swfs|system)/ {
          try_files $uri @rails;
          access_log off;
          gzip_static on;
          
          # to serve pre-gzipped version
          expires max;
          add_header Cache-Control public;
          
          add_header Last-Modified &quot;&quot;;
          add_header ETag &quot;&quot;;
          break;
      }
  
      location @rails {
          proxy_pass http://railsapp;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
          proxy_set_header Host $http_host;
          proxy_redirect off;
      }
  
      # 404 HANDLING
      location = /404.html {
          internal;
      }
  }
  </code></pre>
  <p>I also tried to modify the proxy_pass for my proper url, but it didn't work. Basically, there would always be a &quot;/portal/&quot; after the url, so like &quot;mytestwebsite.com/portal/signin&quot;. All of this is running in a docker container and the root path does seem to be correct from what I checked.</p>
  <p>If anyone has an idea as to why it doesn't work, feel free to point me in the good direction! Thanks!</p>