webui: serve via nginx

Serve the mostly pre-compressed static webui content via nginx. If nginx
can't find a static file, proxy the URI back to the rest server.

A follow-up commit will remove code that serves webui from the
phosphor-rest-server.

Tested:
- The webui, rest server and bmcweb seem to be working as before.
- curl -H "Accept-Encoding: gzip" https://<witherspoon>/foo.html
  is served compressed content.
- curl https://<witherspoon>/foo.html is served uncompressed
  content.

Change-Id: Ice443f00a467f3558f28d697261df4f23278f420
Signed-off-by: Deepak Kodihalli <dkodihal@in.ibm.com>
diff --git a/meta-openbmc-machines/meta-openpower/meta-ibm/recipes-httpd/nginx/files/nginx.conf b/meta-openbmc-machines/meta-openpower/meta-ibm/recipes-httpd/nginx/files/nginx.conf
index 89e575a..7d65183 100644
--- a/meta-openbmc-machines/meta-openpower/meta-ibm/recipes-httpd/nginx/files/nginx.conf
+++ b/meta-openbmc-machines/meta-openpower/meta-ibm/recipes-httpd/nginx/files/nginx.conf
@@ -65,12 +65,29 @@
         ssl_prefer_server_ciphers   on;
 
         location / {
+                # This location lets us serve the static pre-compressed webui
+                # content (rooted at /usr/share/www). Also if the URI points to
+                # something else (that is unmatched by other locations), we
+                # fallback to the rest server. This approach is based on the
+                # guide at https://docs.nginx.com/nginx/admin-guide/web-server/serving-static-content.
+                root /usr/share/www;
+                # For clients that support gzip encoding, serve them
+                # pre-compressed gzip content. For clients that don't,
+                # uncompress on the BMC. The module gunzip requires
+                # gzip_static to be set to 'always'; gzip_static is the
+                # module that serves compressed content for clients that
+                # support gzip.
+                gunzip on;
+                gzip_static always;
+                try_files $uri $uri/ @rest_server;
+        }
+        location @rest_server {
                 # Use 127.0.0.1 instead of localhost since nginx will
                 # first use ipv6 address of ::1 which the upstream server
                 # is not listening on. This generates an error msg to
                 # the journal. Nginx then uses the 127.0.0.1 and everything
                 # works fine but want to avoid the error msg to the log.
-                proxy_pass http://127.0.0.1:8081/;
+                proxy_pass http://127.0.0.1:8081;
 
                 # WebSocket support
                 proxy_http_version 1.1;