summaryrefslogtreecommitdiffstats
path: root/roles/git/files/etc/nginx/sites-available/git
blob: 3f2bc7fd11bba55b5dfc2eff3c364677dc658c0e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
server {
    listen      80;
    listen [::]:80;

    server_name  git.fripost.org;

    include /etc/lacme/nginx.conf;

    access_log /var/log/nginx/git.access.log;
    error_log  /var/log/nginx/git.error.log info;

    location / {
        return 301 https://$host$request_uri;
    }
}


server {
    listen      443 ssl http2;
    listen [::]:443 ssl http2;

    server_name  git.fripost.org;

    access_log /var/log/nginx/git.access.log;
    error_log  /var/log/nginx/git.error.log info;

    include snippets/headers.conf;
    add_header Content-Security-Policy
               "default-src 'none'; img-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self'";

    include snippets/ssl.conf;
    ssl_certificate     ssl/git.fripost.org.pem;
    ssl_certificate_key ssl/git.fripost.org.key;
    include             snippets/git.fripost.org.hpkp-hdr;

    gzip on;
    gzip_vary on;
    gzip_min_length 256;
    gzip_types application/javascript application/json application/xml image/svg+xml image/x-icon text/css text/plain;

    location ^~ /static/ {
        expires 30d;
        alias /usr/share/cgit/;
    }

    # disallow push over HTTP/HTTPS
    location ~ "^/.+/git-receive-pack$" { return 403; }

    location ~ "^/.+/(?:info/refs|git-upload-pack)$" {
        limit_except GET POST { deny all; }
        fastcgi_buffering off;
        gzip off;

        fastcgi_param SCRIPT_FILENAME /usr/lib/git-core/git-http-backend;
        fastcgi_param NO_BUFFERING    "";

        # cf. git-http-backend(1)
        fastcgi_param GIT_PROJECT_ROOT /var/lib/gitolite/repositories;
        fastcgi_param PATH_INFO        $uri;
        fastcgi_param CONTENT_TYPE     $content_type;
        fastcgi_param QUERY_STRING     $query_string;
        fastcgi_param REQUEST_METHOD   $request_method;
        fastcgi_pass unix:/run/git-http-backend.socket;
    }

    location = /robots.txt  { root /usr/share/cgit; }
    location = /favicon.ico { root /usr/share/cgit; }

    # send all other URLs to cgit
    location / {
        fastcgi_param SCRIPT_FILENAME  /usr/lib/cgit/cgit.cgi;
        fastcgi_param PATH_INFO        $uri;
        fastcgi_param CONTENT_TYPE     $content_type;
        fastcgi_param QUERY_STRING     $query_string;
        fastcgi_param REQUEST_METHOD   $request_method;
        fastcgi_pass unix:/run/cgit.socket;
    }
}