Ubuntu18.04 Server安装Nginx+Git服务

安装

需要安装的包有 nginx, fcgiwrap, git. 其中git在Ubuntu18.04 Server安装时已经默认安装了. 需要安装的是前两个

而fcgiwrap是在 universe 区域里面(找一个包时如果不确定是在那个区域, 可以在 https://packages.ubuntu.com/ 上面先查一下

默认的Ubuntu18.04 Server的 /etc/apt/source.list 内容是这样的

deb http://cn.archive.ubuntu.com/ubuntu bionic main
deb http://cn.archive.ubuntu.com/ubuntu bionic-security main
deb http://cn.archive.ubuntu.com/ubuntu bionic-updates main 

需要在main后面加上universe, 否则apt install 会找不到 fcgiwrap

deb http://cn.archive.ubuntu.com/ubuntu bionic main universe
deb http://cn.archive.ubuntu.com/ubuntu bionic-security main universe
deb http://cn.archive.ubuntu.com/ubuntu bionic-updates main universe

然后执行 sudo apt update 后, 就可以通过 sudo apt install fcgiwrap安装了.

创建Git工作目录

这里将git工作目录放置到 /var/www/git , 将目录权限设置为 www-data (和nginx的worker一致)

cd /var/www/
sudo mkdir git
sudo chown -R www-data:www-data git/
cd git/
sudo mkdir sandbox.git
cd sandbox.git/
sudo git --bare init
sudo git update-server-info
sudo chown -R www-data:www-data .

在sandbox.git目录下, 设置目录和文件权限

# 设置目录为755
sudo find . -type d -exec chmod 755 {} +
# 设置文件为644
sudo find . -type f -exec chmod 644 {} +

配置Nginx

修改nginx默认的配置文件

# backup the default config
sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/default-bak
# Open the file for editing with the command:
sudo vi /etc/nginx/sites-available/default

在默认的 location / {} 后面, 增加下面的内容

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
    }
#增加的内容
    location ~ (/.*) {
        root /var/www/git;
        client_max_body_size 0; # Git pushes can be massive, prevent suddenly cut the connection
        auth_basic "Git Login"; # For displaying
        auth_basic_user_file "/var/www/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 /var/www/git; # 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
    }

创建密码文件

可以通过 htpasswd -c /var/www/git/htpasswd milton 来创建, 也可以通过 openssl passwd -apr1 生成口令来手动创建

然后重启nginx

sudo systemctl restart/reload nginx

这时候就可以通过git客户端连接测试了.

添加新Git仓库

sudo mkdir sandbox.git
cd sandbox.git/

sudo git --bare init
sudo git update-server-info
sudo chown -R www-data:www-data .
# 设置目录为755
sudo find . -type d -exec chmod 755 {} +
# 设置文件为644
sudo find . -type f -exec chmod 644 {} +

原文地址:https://www.cnblogs.com/milton/p/11047115.html

时间: 2024-08-30 07:36:24

Ubuntu18.04 Server安装Nginx+Git服务的相关文章

ubuntu 12.04 server 安装nginx

下载源码: wget http://nginx.org/download/nginx-1.6.1.tar.gz 解压,编译安装 ./configure ./configure: error: the HTTP rewrite module requires the PCRE library. You can either disable the module by using --without-http_rewrite_module option, or install the PCRE li

EOS 在ubuntu18.04上安装EOS

在ubuntu18.04上安装EOS 在ubuntu18.04上安装EOS的目的: 把交易所的eos转到eos主网,防止交易所跑路或者交易所被黑客攻击 在不联网的安全环境下,用eos官方的命令行工具,创建自己的公钥和私钥(待续) 用eos官方的命令行工具,创建钱包,执行转账,购买RAM等(待续) 本笔记包括二部分 一, 在虚拟机vbox上安装ubuntu18.04 二, 在ubuntu18.04上编译eos源代码,再安装eos 第一部分:在虚拟机vbox上安装ubuntu18.04 1,根据自己

Ubuntu18.04下安装Sublime Text3!

这几天安装了Ubuntu18.04,然后在里面安装Sublime Text3,结果各种问题!各种BUG!试了网上各种办法!尼玛!都是坑爹的啊! 最后还是楼主自己解决了-- 废话不多说,直接按顺序执行下面命令开始安装! wget -qO - https://download.sublimetext.com/sublimehq-pub.gpg | sudo apt-key add - 1 sudo apt-get install apt-transport-https 1 echo "deb htt

Ubuntu18.04 离线安装 docker

Ubuntu18.04 离线安装 dockerhttps://blog.csdn.net/u012814856/article/details/804231851. 将下载下来的文件夹中的 4 个文件放到 Ubuntu 任意一个文件中(一般用户目录下) 2. 在同一目录下运行这行命令离线安装 docker: dpkg -i *.deb # chattr -i /etc/groupgroupadd dockersystemctl enable docker && systemctl star

在ubuntu18.04中安装opencv_contrib-3.2.0采坑教程

由于最近要在OpenCV3中使用SIFT和SURF特征提取,而自从OpenCV2升级到OpenCV3版本后,SIFT.SURF等这些算法都被移出opencv默认项目库,而被放到叫opencv_contrib的项目库.因此需要手动下载opencv和opencv_contrib的源码,然后将两个源码放在一起手动编译安装. 由于我的电脑是VMware虚拟机跑的ubuntu18.04,并且ubuntu18.04中安装了ROS-melodic,而ROS-melodic装完后默认就把opencv-3.2.0

Ubuntu18.04 X64安装typro

Ubuntu18.04 X64安装typro # or run: # sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys BA300B7755AFCFAE wget -qO - https://typora.io/linux/public-key.asc | sudo apt-key add - # add Typora's repository sudo add-apt-repository 'deb https://ty

【阿里云】在 Windows Server 2016 下使用 FileZilla Server 安装搭建 FTP 服务

 Windows Server 2016 下使用 FileZilla Server 安装搭建 FTP 服务 一.安装 Filezilla Server 下载最新版本的 Filezilla Server: https://filezilla-project.org/download.php?type=server . 在本地也需要安装 FileZilla Client :https://filezilla-project.org/download.php?type=client 二.配置FTP端口

在Ubuntu18.04上安装Nvidia驱动

拿到了一台新机子,带显卡的那种,当然是各种倒腾了!于是我又一天装了三遍机子来进行各种尝试熟悉配置啥的. 所以首先是在裸机上安装Nvidia驱动. 环境:Ubuntu18.04 刚安装完系统,当然是把软件更新器提出的下载更新给下载一下了.所以首先应该是 1 sudo apt-get update 当然,上述是系统主动提出的更新,并没有输入指令啦~ 接下来,为了安装较新的驱动,先将ppa源加入 1 sudo add-apt-repository ppa:graphics-drivers/ppa 2

[转帖]Ubuntu 18.04 server安装图形界面及realvnc远程桌面连接

Ubuntu 18.04 server安装图形界面及realvnc远程桌面连接 https://blog.csdn.net/networken/article/details/88938304 转帖 学习一下. 版权声明:本文为博主原创文章,转载请注明出处. https://blog.csdn.net/networken/article/details/88938304 ubuntu server安装图形界面 sudo passwd root su root apt-get update apt