Corgis,Pictures,Tech

nginx and File Size Limits


So after writing my first post and then adding a nice "Coding" picture as the post banner, I went to change the photo for my main page. Ghost informed me that the file/image was over the size limit.

Now the irony is not lost on me that I have now changed theme (Coder is really nice) to one that doesn't have images for the posts or main page but for adding images *inside* posts I wanted to get rid of the file upload limit.

After a quick Google (well DuckDuckGo) it seems this is quite a common issue and it requires adding -

client_max_body_size 100m;

Now client_max_body_size is normally set to 1mb, for my purposes 100mb will be enough for my blog.

Now changing the config is easy but I wanted to be able to deploy this from scratch in the future with this change already in place. I needed to do 2 things -

  1. Update the docker-compose.yml file with your customization's and add the following line (under the nginx-proxy section)-
- "./my_custom_proxy_settings.conf:/etc/nginx/conf.d/my_custom_proxy_settings.conf"

So the file looks like so -

version: '2'
services:

  ghost:
    image: ghost:latest
    restart: always
    environment:
    NODE_ENV: production
    url: https://<Your Domain Here>
    mail__transport: SMTP
    mail__options__service: Mailgun
    mail__options__auth__user: <My Mailgun User>
    mail__options__auth__pass: <My Mailgun Password>
    VIRTUAL_HOST: <Your Domain Here>
    LETSENCRYPT_HOST: <Your Domain Here>
    LETSENCRYPT_EMAIL: <Your Email Here>
    volumes:
      - ~/data/ghost:/var/lib/ghost/content

  nginx-proxy:
    image: jwilder/nginx-proxy
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - "/etc/nginx/vhost.d"
      - "/usr/share/nginx/html"
      - "/var/run/docker.sock:/tmp/docker.sock:ro"
      - "/etc/nginx/certs"
      - "./my_custom_proxy_settings.conf:/etc/nginx/conf.d/my_custom_proxy_settings.conf"
  
  letsencrypt-nginx-proxy-companion:
    image: jrcs/letsencrypt-nginx-proxy-companion
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock:ro"
    volumes_from:
      - "nginx-proxy"
docker-compose.yml

2. Create a file called my_custom_proxy_settings.conf and add the following -

client_max_body_size 100m;
my_custom_proxy_settings.conf 

Now all you have to do is create a folder on your server (I called my sslghost) and upload the 2 files in to that folder.

Once you have done that you can move in to that folder and run -

docker-compose up

You will see the screen fill up as docker does its thing, once it is settled you can Ctrl + C out and then run -

docker-compose up -d

Then the containers will now run in the background with no file size upload limit!

So I have a blog - Again


So, again I have set up a blog. I didn't mean to if I am being honest, I was just playing around with Docker. I had some requirements to try and get this set up -

  1. Use Docker for all web applications I was going to be using.
  2. SSL support via Lets Encrypt/Certbot
  3. Run it on a VPS.

The 3rd point was easy, Normally I use DigitalOcean for this sort of thing, but while setting up an account with $50 credit, It didn't like my bank cards (Monzo and B seem to appear as top-up credit cards/don't work and I didn't want to use one of my main bank cards online.) so I ended up getting free credit at Vultr and quite frankly seems exactly same to DigitalOcean, and within 15 minutes of signing up I had a Ubuntu VM with Docker up and running.

SSH keys in place and domain name pointing in the right direction, I decided to use Portainer as a GUI for Docker, This seems at the moment to work well enough for my needs and it runs in its own container. Super easy install!

Now for the Blog

The first issue I seemed to come across was that nginx was not normally ran in a container or guides assumed I already had an SSL certificate.

I came across Miles McBain's A Fully Dockerised HTTPS Ghost Blog Post and quite frankly it was exactly what I was looking for with my setup.

The only slight changes to docker-compose.yml I made -

  1. Updating the tag to use the latest version of Ghost - Changing image: ghost:1.21.3-alpine to image: ghost:latest
  2. Updating with all my Domain Details/Mailgun (at this point not really checked the mailgun stuff as I have 2FA setup so didn't enter it in to my docker-compose.yml file)
  3. Removing all the rstudio stuff. Don't need or want it.

So my docker-compose.yml file was as follows -

version: '2'
services:

  ghost:
    image: ghost:latest
    restart: always
    environment:
    NODE_ENV: production
    url: https://<Your Domain Here>
    mail__transport: SMTP
    mail__options__service: Mailgun
    mail__options__auth__user: <My Mailgun User>
    mail__options__auth__pass: <My Mailgun Password>
    VIRTUAL_HOST: <Your Domain Here>
    LETSENCRYPT_HOST: <Your Domain Here>
    LETSENCRYPT_EMAIL: <Your Email Here>
    volumes:
      - ~/data/ghost:/var/lib/ghost/content

  nginx-proxy:
    image: jwilder/nginx-proxy
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - "/etc/nginx/vhost.d"
      - "/usr/share/nginx/html"
      - "/var/run/docker.sock:/tmp/docker.sock:ro"
      - "/etc/nginx/certs"
 
  letsencrypt-nginx-proxy-companion:
    image: jrcs/letsencrypt-nginx-proxy-companion
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock:ro"
    volumes_from:
      - "nginx-proxy"

After a wee while after uploading and running that in Portainer, just navigating to baconstrip.org.uk pushed me to use HTTPS and I saw the default Ghost install. Then it was a case of adding /ghost to the URL and I started configuring my very own SSL enabled fully docker container-ed blog.