Skip to content

Instantly share code, notes, and snippets.

@mstroeck
Forked from massar/server-git.conf
Created September 22, 2015 14:34

Revisions

  1. @massar massar created this gist Mar 6, 2014.
    43 changes: 43 additions & 0 deletions server-git.conf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,43 @@
    # Example nginx + git HTTP Smart mode (git-http-backend) + HTTP Authentication + HTTPS redirect
    # jeroen@massar.ch - http://jeroen.massar.ch

    server {
    listen 192.0.1.1:80;
    listen [2001:db8::1]:80;

    # Redirect all non-HTTPS traffic to the HTTPS variant
    return 301 https://$host$request_uri;
    }

    server {
    listen 192.0.1.1:443;
    listen [2001:db8::1]:443;

    root /www/empty/;
    index index.html;

    server_name git.example.com;
    access_log /var/log/nginx/access.log;

    #error_page 404 /404.html;

    # ... ssl params ...

    auth_basic "Restricted";
    auth_basic_user_file /www/htpasswd;

    location ~ /git(/.*) {
    # Set chunks to unlimited, as the body's can be huge
    client_max_body_size 0;

    fastcgi_param SCRIPT_FILENAME /usr/lib/git-core/git-http-backend;
    include fastcgi_params;
    fastcgi_param GIT_HTTP_EXPORT_ALL "";
    fastcgi_param GIT_PROJECT_ROOT /git;
    fastcgi_param PATH_INFO $1;

    # Forward REMOTE_USER as we want to know when we are authenticated
    fastcgi_param REMOTE_USER $remote_user;
    fastcgi_pass unix:/var/run/fcgiwrap.socket;
    }
    }