Skip to content

Instantly share code, notes, and snippets.

@ei-grad
Created March 21, 2020 20:07
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save ei-grad/2d70c40c7956939f2564b988025ed665 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
@AndrewTsao
Copy link

It's not working. I fix it by this:

proxy_ignore_headers "Set-Cookie";
proxy_hide_header "Set-Cookie";

reference: https://stackoverflow.com/questions/9230812/nginx-as-cache-proxy-not-caching-anything

Thank you! Anyway.

@ei-grad
Copy link
Author

ei-grad commented Oct 26, 2021

conda CLI (and conda repository upstream) didn't use cookies at the moment of writing, thanks for notice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment