Skip to content

Instantly share code, notes, and snippets.

@Foat
Forked from ei-grad/conda.conf
Created May 17, 2022 07:38
Show Gist options
  • Save Foat/eea7becb28f73d3a0cb7accde89ea23f to your computer and use it in GitHub Desktop.
Save Foat/eea7becb28f73d3a0cb7accde89ea23f to your computer and use it in GitHub Desktop.
Nginx caching proxy for conda
# /etc/nginx/conf.d/conda.conf
proxy_cache_path /var/cache/nginx/conda levels=2:2 keys_zone=conda:100m inactive=14d max_size=10g;
upstream conda.anaconda.org {
server 104.17.92.24:443;
server 104.17.93.24:443;
}
server {
listen 80;
server_name conda.anaconda.org conda-proxy;
location / {
proxy_cache conda;
proxy_cache_valid 200 365d;
proxy_cache_key $request_uri;
proxy_pass https://conda.anaconda.org;
proxy_http_version 1.1;
proxy_set_header Host "conda.anaconda.org";
proxy_set_header Connection "";
proxy_intercept_errors on;
error_page 302 = @handle_redirect;
}
location @handle_redirect {
proxy_cache conda;
proxy_cache_valid 200 365d;
set $saved_uri '$uri';
proxy_cache_key $saved_uri;
set $saved_redirect_location '$upstream_http_location';
proxy_pass $saved_redirect_location;
proxy_http_version 1.1;
proxy_set_header Connection "";
resolver 127.0.0.1; // CHANGE IF THERE IS NO LOCAL DNS CACHE
}
location ~ .json$ {
proxy_pass https://conda.anaconda.org;
proxy_cache_valid 200 1d;
proxy_cache_key $request_uri;
proxy_http_version 1.1;
proxy_set_header Host "conda.anaconda.org";
proxy_set_header Connection "";
}
}
echo 127.0.0.123 conda-proxy >> /etc/hosts
conda config --add channels http://conda-proxy/main
conda config --add channels http://conda-proxy/conda-forge
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment