• Home
  • Git
  • Setup git server with nginx

Setup git server with nginx

linkaiyi
Follow

Setup git server with nginx

install necessary packages, besides git, fcgiwrap and apache2-utils are important. Nginx does not have fastcgi support, apache2-utils offers authentication control as well

sudo apt-get install nginx git nano fcgiwrap apache2-utils -y

make root directory for git

sudo mkdir /var/www/html/git
sudo chown -R www-data:www-data /var/www/html/git # important to set owner of the directory to www-data, otherwise there will be auth error
sudo htpasswd -c /var/www/html/git/htpasswd linkaiyi # generate the password for user linkaiyi and encrypt the password

config nginx for the git

# git server configuration
#
server {
        listen 8080;
        listen [::]:8080;


        root /home/linkaiyi/git;
        client_max_body_size 0; # Git pushes can be massive, just to make sure nginx doesn't suddenly cut the connection add this.

        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html;

        server_name _;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
        }

        location ~ (/.*) {
            auth_basic "Git Login"; # Whatever text will do.
            auth_basic_user_file "/home/linkaiyi/git/htpasswd";
            include /etc/nginx/fastcgi_params; # Include the default fastcgi configs
            fastcgi_param SCRIPT_FILENAME /usr/lib/git-core/git-http-backend; # Tells fastcgi to pass the request to the git http backend executable
            fastcgi_param GIT_HTTP_EXPORT_ALL "";
            fastcgi_param GIT_PROJECT_ROOT /home/linkaiyi/git; # /home/linkaiyi/git is the location of all of your git repositories.
            fastcgi_param REMOTE_USER $remote_user;
            fastcgi_param PATH_INFO $1; # Takes the capture group from our location directive and gives git that.
            fastcgi_pass  unix:/var/run/fcgiwrap.socket; # Pass the request to fastcgi
        }

}

set remote origin

git remote add http://linkaiyi@h2855032.stratoserver.net:8080/mdm.git
Object has 0 attachments

Was this article helpful?

This article is viewed 70 times!

Recent Viewed Articles

Related Articles

0 Comments

Leave a Comment

Support