# In order for this server to work, you need to install some dependencies:
# apt install nginx git fcgiwrap
#
# Also, ensure fcgiwrap is running as a daemon. On Ubuntu, this should happen automatically.
server {
listen 80 default_server;
listen [::]:80 default_server;
# Replace this with the path to your mirror directory.
root /path/to/my-mirror;
# Replace this with the domain name you're serving the mirror from.
server_name panamax.internal;
location / {
autoindex on;
}
location ~ /crates.io-index(/.*) {
# Replace this path with the path to crates.io-index in your mirror directory.
fastcgi_param GIT_PROJECT_ROOT /path/to/my-mirror/crates.io-index;
include fastcgi_params;
fastcgi_pass unix:/var/run/fcgiwrap.socket;
fastcgi_param SCRIPT_FILENAME /usr/lib/git-core/git-http-backend;
fastcgi_param GIT_HTTP_EXPORT_ALL "";
fastcgi_param PATH_INFO $1;
}
# Rewrite the download URLs to match the proper crates location.
rewrite "^/crates/([^/])/([^/]+)$" "/crates/1/$1/$2" last;
rewrite "^/crates/([^/]{2})/([^/]+)$" "/crates/2/$1/$2" last;
rewrite "^/crates/([^/])([^/]{2})/([^/]+)$" "/crates/3/$1/$1$2/$3" last;
rewrite "^/crates/([^/]{2})([^/]{2})([^/]*)/([^/]+)$" "/crates/$1/$2/$1$2$3/$4" last;
}