nginx-proxy: file upload limitation

#ansible #jwilder #nginx-proxy

 

Recently, I've found myself unable to upload images to this blog, and for a while I thought it was some bug in my code as a result of updating some dependencies or something.

However, after some debugging it turned out that it was the way I have my infrastructure setup. The server that hosts www.jasonernst.com runs an nginx-proxy and this blog runs behind that. I also serve a few other websites from it as well (it also makes for an easy setup with letsenrypt).

When I tried to upload a file, I was getting a 413 Request Entity Too Large. At first I thought it was something related to gin-gonic, which this site is based on, and I increased the max size there to no effect. I then thought it might be some CORS related stuff, but nothing I tried there worked either (there have been some updates with how CORS and gin-gonic work together since I last took a look at this).

Finally, when I increased the javascript debugging, I noticed that the error was coming from nginx, and I realized what happened. Here's how I fixed it in my ansible setup:

- name: Create nginx directory on host
  tags: proxy
  become: true
  file:
    path: /etc/nginx/conf.d
    state: directory
    mode: '755'
    owner: root
    group: root

- name: Copy nginx config to host
  tags: proxy
  become: true
  copy:
    src: conf/proxy.conf
    dest: /etc/nginx/conf.d
    mode: '644'
    owner: root
    group: root

- name: pull and run the nginx reverse proxy
  tags: proxy
  vars:
    ansible_python_interpreter: "/usr/bin/env python3-docker"
  docker_container:
    name: nginx-proxy
    image: jwilder/nginx-proxy
    published_ports: 80:80,443:443
    volumes: /etc/nginx/conf.d:/etc/nginx/conf.d,vhost:/etc/nginx/vhost.d,html:/usr/share/nginx/html,dhparam:/etc/nginx/dhparam,certs:/etc/nginx/certs:ro,/var/run/docker.sock:/tmp/docker.sock:ro
    network_mode: bridge
    restart_policy: unless-stopped

(Created the directory on the host that is running the containers, added the config file defined in ansible, and then added a mapped volume from the config directory on the host into the container.

I then added a file in conf/proxy.conf at the same level as the task with these contents:

client_max_body_size 100m;

Comments (0)


Leave a Comment

Log in to leave a comment.

Most Recent Post

Searching the Parts of the Internet Google Doesn't: Five Years of darksearch.xyz

There's a whole slice of the internet that's public but almost impossible to search. Content on IPFS is addressed by what it is (a content hash, the CID) rather than where it is, so there's no domain to crawl, no robots.txt, and no single server to point a search engine at. If you don't already have...