• 0 Posts
  • 8 Comments
Joined 3 years ago
cake
Cake day: November 21st, 2023

help-circle



  • Your whole life becomes much simpler when you use docker.

    Elevator pitch: Docker containers are preconfigured services which run isolated from the rest of your system and only expose individual directories you map into the container. These directories are the persistence part of the application and survive a restart of the container or the host system. Just backup your scripts and the data directories and you have backed up your entire server.

    I have a few scripts as examples. ‘cd “$(dirname “$0”)”’ changes to the directory the script is stored in, and therefore will create and map data directories from that parent directory.

    Letsencrypt proxy companion will set up a single listener for web and ssl traffic, setup virtual hosts automatically, and setup SSL, all with automations.

    First, you need letsencrypt nginx proxy companion:

    #!/bin/bash
    

    cd “$(dirname “$0”)”

    docker run --detach
    –restart always
    –name nginx-proxy
    –publish 80:80
    –publish 443:443
    –volume $(pwd)/certs:/etc/nginx/certs
    –volume $(pwd)/vhost:/etc/nginx/vhost.d
    –volume $(pwd)/conf:/etc/nginx/conf.d
    –volume $(pwd)/html:/usr/share/nginx/html
    –volume /var/run/docker.sock:/tmp/docker.sock:ro
    –volume $(pwd)/my_proxy.conf:/etc/nginx/conf.d/my_proxy.conf:ro
    –volume $(pwd)/nginx.conf:/etc/nginx/nginx.conf:ro
    –volume $(pwd)/acme:/etc/acme.sh
    jwilder/nginx-proxy

    docker run --detach
    –restart always
    –name nginx-proxy-letsencrypt
    –volumes-from nginx-proxy
    –volume /var/run/docker.sock:/var/run/docker.sock:ro
    –env “DEFAULT_EMAIL=YOUR_EMAIL_ADDRESS_GOES_HERE@MYDOMAIN.COM”
    jrcs/letsencrypt-nginx-proxy-companion

    Then for each service, you can start with a docker command as well with a few extra environment variables. Here is one for nextcloud:

    docker run -d \
    

    –name nextcloud
    –hostname cloud.MYDOMAIN.COM
    -v $(pwd)/data:/var/www/html
    -v $(pwd)/php.ini:/usr/local/etc/php/conf.d/zzz-custom.ini
    –env “VIRTUAL_HOST=cloud.MYDOMAIN.COM”
    –env “LETSENCRYPT_HOST=cloud.MYDOMAIN.COM”
    –env “VIRTUAL_PROTO=http”
    –env “VIRTUAL_PORT=80”
    –env “OVERWRITEHOST=cloud.MYDOMAIN.COM”
    –env “OVERWRITEPORT=443”
    –env “OVERWRITEPROTOCOL=https”
    –restart unless-stopped
    nextcloud:25.0.0

    And Plex (/dev/dri is quicksync for hardware transcode):

    docker run \
    --device /dev/dri:/dev/dri \
    --restart always \
    -d \
    --name plex \
    --network host \
    -e TZ="America/Chicago" \
    -e PLEX_CLAIM="claim-somerandomcharactershere" \
    -v $(pwd)/config:/config \
    -v /my/media/directory/on/host/system:/media \
    plexinc/pms-docker
    

    Obsidian:

    docker run --rm -d \
    

    –name obsidian
    -v $(pwd)/vaults:/vaults
    -v $(pwd)/config:/config
    –env "VIRTUAL_HOST=obsidian.MYDOMAIN.COM "
    –env "LETSENCRYPT_HOST=obsidian.MYDOMAIN.COM "
    –env “VIRTUAL_PROTO=http”
    –env “VIRTUAL_PORT=8080”
    ghcr.io/sytone/obsidian-remote:latest




  • So I assume you have a web server somewhere which is configured to host virtual hosts in some regard. You need to set up a virtual host which is configured to respond to requests for mydomain.com and reply with a redirect to aa.mydomain.com. The DNS for the domain root must be an A record, so you will have to set the IP address for your web server on the A record for mydomain.com. How exactly this looks and what sticky points you have in setting this up depends on what your web server setup is like - maybe you have this all working, but if not, if this is just an apache or nginx install, then we need to work through setting up the virtual host, or if this is a docker style nginx letsencrypt manager, then thats another set of configuration issues.

    Let me know how far you’ve gotten, or if nowhere at all and you need a recommendation for how to do this, let me know. Let me know a little more about your web server environment that responds to mydomain.com if you have one set up (linux? windows? router with pfsense?)

    The way I do this is my router forwards all http and https traffic to my web server running ubuntu, and docker-letsencrypt-nginx-proxy-companion handles all the virtual hosts. Then if I wanted to create a redirect for a single domain, I would make a docker container that served an nginx server and have it configured with a redirect. But I must acknowledge I’ve been a sysadmin for 10 years and there may be more user friendly turnkey ways to do this, I’m just doing what works for me.