Skip to content

Instantly share code, notes, and snippets.

@ToxicFrog
Created April 29, 2020 22:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ToxicFrog/a3c31dbbc4222d079d1f69217d3f9759 to your computer and use it in GitHub Desktop.
Save ToxicFrog/a3c31dbbc4222d079d1f69217d3f9759 to your computer and use it in GitHub Desktop.
{ config, pkgs, lib, ... }:
{
services.nginx = {
enable = true;
recommendedProxySettings = true;
recommendedGzipSettings = true;
recommendedOptimisation = true;
recommendedTlsSettings = true;
virtualHosts."library.example.com" = {
# Automatically redirect HTTP requests to HTTPS
forceSSL = true;
# Automatically get certs from Let's Encrypt
enableACME = true;
# Reverse proxy / to ebook library
locations."/".proxyPass = "http://127.0.0.1:26657/";
# Reverse proxy /comics to comic library
locations."/comics".proxyPass = "http://127.0.0.1:2202";
# Inject some JS that improves the UI into all responses from the comic server, since
# this is easier than patching the server itself.
locations."= /comicreader.js".alias = pkgs.copyPathToStore ./comicreader.js;
# extraConfig lets you insert arbitrary nginx config, so you can e.g. override
# the proxy_set_header settings from recommendedProxySettings if needed, or
# do other weird stuff.
locations."/comics".extraConfig = ''
sub_filter '</head>' '<script type="text/javascript" src="/comicreader.js"></script></head>';
sub_filter_last_modified on;
sub_filter_once on;
'';
};
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment