Nginx HTTP authorization only for git push Nginx HTTP authorization only for git push nginx nginx

Nginx HTTP authorization only for git push


Try separating the locations:

server {  listen 443 ssl;  server_name git.example.com;  ssl_certificate /fullchain.pem;  ssl_certificate_key /privkey.pem;  location ~ ^.*\.git/(HEAD|info/refs|objects/info/.*|git-recieve-pack) {    # Do your stuff   location ~ ^.*\.git/git-upload-pack {    auth_basic "Restricted";    auth_basic_user_file /usr/share/nginx/htpasswd;    # Do your stuff 


You can auth/deny based on request_method.

        if ($request_method ~* "^(POST|PUT|DELETE)$" ) {                # check if is there a cookie or something like that                # and redirect to login if not        }