Last active
          February 2, 2021 10:35 
        
      - 
      
- 
        Save alexamies/71f17f878a1efb764e631920ac3b7076 to your computer and use it in GitHub Desktop. 
Revisions
- 
        alexpamies renamed this gist Oct 5, 2018 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewingFile renamed without changes.
- 
        alexpamies revised this gist Sep 12, 2018 . 1 changed file with 4 additions and 2 deletions.There are no files selected for viewingThis file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -72,8 +72,10 @@ cp test.json docker-nginx-brotli/. Edit the docker-nginx-brotli/Dockerfile so that the test files are embedded directly in the Docker image, adding these lines: ``` RUN mkdir -p /usr/share/nginx/www/ RUN mkdir -p /var/log/app_engine/ COPY test.html /usr/share/nginx/www/index.html COPY *.json /usr/share/nginx/www/ ``` Edit nginx.conf, adding these lines 
- 
        alexpamies revised this gist Sep 12, 2018 . 1 changed file with 58 additions and 6 deletions.There are no files selected for viewingThis file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,17 +1,19 @@ # Using NGINX with Brotli This Gist demonstrates enabling Brotli in Nginx in App Engine Flex using a custom container. ## Running in Docker locally Use of basic Nginx image adapting the example nginx.conf adapted from [Full Example Configuration](https://www.nginx.com/resources/wiki/start/topics/examples/full/) ``` docker run --rm -itd --name test-nginx \ -v $(pwd):/usr/share/nginx/html:ro \ -v $(pwd)/nginx.conf:/etc/nginx/nginx.conf:ro \ -d -p 8080:80 \ nginx ``` Test gzip with Curl: ``` curl -H "Accept-Encoding: gzip" -I http://localhost:8080/test.json ``` @@ -26,7 +28,7 @@ Stop the server docker stop test-nginx ``` Get the Brotli plug-n ``` git clone https://github.com/fholzer/docker-nginx-brotli.git cd docker-nginx-brotli @@ -56,3 +58,53 @@ Build and run again then test Brotli with for a json file: curl -H "Accept-Encoding: br" -I http://localhost:8080/test.json ``` ## App Engine Flex The instructions here are adapted from the [Quickstart for Custom Runtimes in the App Engine Flexible Environment](https://cloud.google.com/appengine/docs/flexible/custom-runtimes/quickstart) Copy the test files to be served to docker-nginx-brotli directory ``` cp test.html docker-nginx-brotli/. cp test.json docker-nginx-brotli/. ``` Edit the docker-nginx-brotli/Dockerfile so that the test files are embedded directly in the Docker image, adding these lines: ``` COPY *.html /usr/share/nginx/html/ COPY *.json /usr/share/nginx/html/ ``` Edit nginx.conf, adding these lines ``` access_log /var/log/app_engine/app.log; error_log /var/log/app_engine/app.log; server { listen 8080; root /usr/share/nginx/www; index index.html index.htm; } ``` Build again locally and upload to Google Container Registry ``` PROJECT_ID={Your project} TAG=t1 gcloud config set project $PROJECT_ID docker tag nginx-brotli gcr.io/$PROJECT_ID/nginx-brotli:$TAG docker push gcr.io/$PROJECT_ID/nginx-brotli:$TAG ``` Then deploy to a App Engine using the [gcloud app deploy](https://cloud.google.com/sdk/gcloud/reference/app/deploy) command: ``` cp custom-app.yaml docker-nginx-brotli/app.yaml cd docker-nginx-brotli gcloud app deploy --image-url=gcr.io/$PROJECT_ID/nginx-brotli:$TAG ``` Verify the result ``` curl -H "Accept-Encoding: br" -I https://$PROJECT_ID.appspot.com/index.html curl -H "Accept-Encoding: br" -I https://$PROJECT_ID.appspot.com/test.json ``` 
- 
        alexpamies created this gist Sep 12, 2018 .There are no files selected for viewingThis file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,58 @@ # Using NGINX with Brotli The Nginx Docker image can be used to serve the contents of the current directory can done with the command below. ``` docker run --rm -itd --name test-nginx \ -v $(pwd):/usr/share/nginx/html:ro \ -v $(pwd)/nginx.conf:/etc/nginx/nginx.conf:ro \ -d -p 8080:80 \ nginx ``` The command uses the accompanying configuration file, which is adapted from the example nginx.conf in the Nginx [Full Example Configuration](https://www.nginx.com/resources/wiki/start/topics/examples/full/) to add gzip support for JSON file types. To verify gzip response with Curl use the command: ``` curl -H "Accept-Encoding: gzip" -I http://localhost:8080/test.json ``` You should see a response that includes the header ``` Content-Encoding: gzip ``` Stop the server ``` docker stop test-nginx ``` Get the Brotli plug-n from fholzer, build it, and run with the commands ``` git clone https://github.com/fholzer/docker-nginx-brotli.git cd docker-nginx-brotli docker build -t nginx-brotli . cd .. docker run --rm -itd --name test-nginx -v $(pwd):/usr/share/nginx/html:ro -d -p 8080:80 nginx-brotli ``` Test Brotli with Curl: ``` curl -H "Accept-Encoding: br" -I http://localhost:8080/test.html ``` You should see a line like ``` Content-Encoding: br ``` For this to work with json responses, edit the file docker-nginx-brotli/nginx.conf adding the line ``` brotli_types text/html application/json; ``` Build and run again then test Brotli with for a json file: ``` curl -H "Accept-Encoding: br" -I http://localhost:8080/test.json ``` This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,33 @@ user nginx; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; gzip on; gzip_types text/html application/json; include /etc/nginx/conf.d/*.conf; } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,42 @@ <html> <hread> <title>Test HTML File</title> </head> <body> "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight" </body> </html> This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,36 @@ {"numbers":["one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight", "one","two","three","three","four","five","six","seven","eight"]}