Skip to content

Instantly share code, notes, and snippets.

@cannikin
Last active January 20, 2022 05:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cannikin/ac5558e5c34caeb69a663d21e45ee0ad to your computer and use it in GitHub Desktop.
Save cannikin/ac5558e5c34caeb69a663d21e45ee0ad to your computer and use it in GitHub Desktop.
nginx Config for Redwood Apps
# With this nginx config you'll be able to serve your static assets through nginx
# while serving the API from Redwood. Start your API server with `yarn rw serve api`
# (or better yet have pm2 manage it for you) and static assets will be delivered
# from /web/dist
#
# Static assets will be given max cache headers and gzipped.
#
# Note that this is only the config for a single site, not the entire global
# nginx config settings. Depending on your install, you may have a /etc/nginx/sites-available
# directory. This file goes in there, and then a symlink to it is added in
# /etc/nginx/sites-enabled If you only have a single nginx.conf file you can
# append these config lines to the end. Don't forget to restart nginx!
upstream redwood_server {
server 127.0.0.1:8911 fail_timeout=0;
}
server {
listen 80;
listen [::]:80;
root /path_to_app/web/dist;
server_name myserver.com;
gzip on;
gzip_min_length 1000;
gzip_types application/json text/css application/javascript application/x-javascript;
sendfile on;
keepalive_timeout 65;
error_page 404 /404.html;
error_page 500 /500.html;
location / {
try_files $uri /index.html =404;
}
location ^~ /static/ {
expires max;
add_header Cache-Control public;
}
# if you changed the default value of apiUrl in redwood.toml you'll use that path here instead of /.redwood/functions
location ~ /.redwood/functions(.*) {
rewrite ^/.redwood/functions(.*) $1 break;
proxy_pass http://redwood_server;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment