Comments (8)
nice, thanks @ekeih fwiw here's my Dockerfile using Nginx.
ARG GATSBY_ACTIVE_ENV=production
FROM node:12-buster AS build
RUN yarn global add gatsby-cli
ARG GATSBY_ACTIVE_ENV
ENV GATSBY_ACTIVE_ENV=$GATSBY_ACTIVE_ENV
WORKDIR /app
ADD . ./
RUN yarn install
RUN gatsby build
RUN ls -la **/*
FROM nginx
COPY --from=build /app/public /usr/share/nginx/html
COPY nginx.conf /etc/nginx/nginx.conf
EXPOSE 80
and my nginx.conf
worker_processes 1;
user nginx;
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"';
keepalive_timeout 15;
autoindex off;
server_tokens off;
port_in_redirect off;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
client_max_body_size 64k;
client_header_buffer_size 16k;
large_client_header_buffers 4 16k;
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_types application/javascript application/x-javascript application/rss+xml text/javascript text/css image/svg+xml;
gzip_buffers 16 8k;
gzip_comp_level 6;
access_log /var/log/nginx/access.log main;
server {
listen 80;
server_name neonlaw.com www.neonlaw.com;
autoindex off;
charset utf-8;
error_page 404 /usr/share/nginx/html/404.html;
location / {
if ($http_x_forwarded_proto = "http") {
return 301 https://$server_name$request_uri;
}
root /usr/share/nginx/html;
index index.html indx.htm;
}
location ~* \.(html)$ {
if ($http_x_forwarded_proto = "http") {
return 301 https://$server_name$request_uri;
}
root /usr/share/nginx/html;
add_header Cache-Control "no-store";
expires off;
}
location ~* \.(ico|jpg|jpeg|png|gif|svg|js|jsx|css|less|swf|eot|ttf|otf|woff|woff2|json)$ {
if ($http_x_forwarded_proto = "http") {
return 301 https://$server_name$request_uri;
}
root /usr/share/nginx/html;
add_header Cache-Control "public";
expires +1y;
}
}
}
You'll want to change the server_name
instruction above. I have this setup to be like this repo and also redirect HTTP requests to HTTPS based on the X_FORWARDED_PROTO
HTTP Header passed in from a load balancer (in my case GCP's Load Balancer).
from gatsby-docker.
In case anyone comes here looking for a solution. I wrote a short blog post about mine: https://fotoallerlei.com/blog/post/2020/dockerizing-a-gatsby-site/post
In case the post is offline in the future, the Dockerfile looks like this:
FROM node:13-buster-slim as build
WORKDIR /app
RUN yarn global add gatsby-cli && gatsby telemetry --disable
ADD package.json yarn.lock ./
RUN yarn --production --frozen-lockfile --non-interactive
ADD . ./
RUN gatsby build
FROM abiosoft/caddy:1.0.3-no-stats
RUN echo 'tls off' >> /etc/Caddyfile
COPY --from=build /app/public /srv
The second build stage can be replaced with nginx to be more similar to the original solution of this repo here.
from gatsby-docker.
Hello @ekeih excellent contribution! I read your post, and implementing as it is, it works perfect.
to run it after build ->
docker run --rm -p 2015:2015 "your image name here"
Thanks a lot
from gatsby-docker.
@shicholas thanks! I was able to fix it by removing that last location directive. Turns out .json
is included on that.
from gatsby-docker.
When I tested it a few weeks ago, it seemed both tags, latest and onbuild, include the nginx container. So the onbuild step from the Readme fails because this tag doesn't include Gatsby at all.
from gatsby-docker.
In case anyone comes here looking for a solution. I wrote a short blog post about mine: https://fotoallerlei.com/blog/post/2020/dockerizing-a-gatsby-site/post
In case the post is offline in the future, the Dockerfile looks like this:
FROM node:13-buster-slim as build WORKDIR /app RUN yarn global add gatsby-cli && gatsby telemetry --disable ADD package.json yarn.lock ./ RUN yarn --production --frozen-lockfile --non-interactive ADD . ./ RUN gatsby build FROM abiosoft/caddy:1.0.3-no-stats RUN echo 'tls off' >> /etc/Caddyfile COPY --from=build /app/public /srv
The second build stage can be replaced with nginx to be more similar to the original solution of this repo here.
I still get this warning
[2/4] Fetching packages...
warning [email protected]: Invalid bin field for "url-loader".
It still failes with:
COPY failed: stat /var/lib/docker/tmp/docker-builder102637302/nginx.conf: no such file or directory
error Command failed with exit code 1.
i
from gatsby-docker.
@shicholas hi, how do you set the cache-control for page-data.json
to "public, max-age=0, must-revalidate"
with that nginx setup?
from gatsby-docker.
@daydream05 you could add the string "public, max-age-0, must-revalidate"
to this line https://github.com/NeonLaw/codebase/blob/development/docker/production.nginx.conf#L73
from gatsby-docker.
Related Issues (20)
- how to use onbuild? HOT 1
- Doesn't actually include Gatsby? HOT 9
- CLI / Dev image HOT 10
- doesn't work under service worker HOT 3
- About cache control HOT 1
- allow overrides in nginx configuration HOT 2
- minor typos HOT 1
- Docker build fails on the first line HOT 16
- Can we update caching strategy for page-data.json HOT 1
- nginx config generated by nginx-boot.sh does bogus 301 redirects HOT 4
- HTTPS? HOT 4
- ERROR [build 2/1] ADD public/ /pub HOT 3
- Feat: Cache webp images HOT 1
- Allow overrides of client_max_body_size
- Gatsby 4 support HOT 2
- Docker image outdated HOT 1
- Let's use a Map as they're a lot cheaper when arrays get large
- Blockonlinenet HOT 1
- This has no reason to exist at all.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gatsby-docker.