Use Gogs to build your own Git server

Source: Internet
Author: User
Tags nginx reverse proxy

Reference Document: Http://wenku.baidu.com/link?url=R-Puaq3FWB_2KnTqSYhzoq9-cYCcBtg_Dqm1Gr_ Os35pyqz-f64ncvhlratgq6h8-vn7tinj0kp5nou6aopgeufwsxmr2k3sgxnc9rvtuia

Building Services: Https://mynook.info/blog/post/host-your-own-git-server-using-gogs

Gogs:https://github.com/gogits/gogs

The installation process is divided into these steps:

    • New User;
    • Download the source code compile/download pre-compiled binary package;
    • Run the installation;
    • Configuration adjustment;
    • Configure Nginx reverse proxy;
    • Keep the service running;

Note that by default you have installed MySQL server and Nginx, if not, find out how to install and configure these dependencies yourself. Of course you can also use the SQLite database.

New user

Gogs is run as a git user by default (you should not want a program that can modify the SSH configuration to run with the root user?). )。
Run a sudo adduser git new git user.
su gitLog in as a git user and create a new folder in the Git user's home directory .ssh .

Download unpacking

I used a precompiled binary package. If you need to compile from the source code, please refer to the compilation of the General Go language Project. After downloading, unpack to the place you like, for example, /usr/share/gogs/ or /home/git/gogs/ . The contents of the folder are as follows.

$ ls/home/git/gogs/custom  data  gogs  LICENSE  log  public  readme.md  readme_zh.md  Scripts  Templates
Run the installation

First set up a good database. The file in the Gogs directory scripts/mysql.sql is the database initialization file. Execute mysql -u root -p < scripts/mysql.sql (enter a password) to initialize the database.

Then log in to MySQL to create a new user, Gogs, and assign gogs all permissions for the database to that user.

$ mysql-u root-p> # (enter password) > create user ' gogs ' @ ' localhost ' identified by ' password ';> grant all privileges on gogs.* To ' gogs ' @ ' localhost ';> flush privileges;> exit;

Run the gogs web gogs to run, then access http://服务器IP:3000/ to install, fill out the form after the submission is OK.
Note that 0.6.9.0903 Beta there is a bug in the version that allows you to not add an administrator if you close the registration, so that no users will be able to log on after the installation is complete. So be sure to specify an administrator account at the installation interface.

Configuration adjustment

The configuration file is in the Gogs directory custom/conf/app.ini , which is a text file in INI format. For detailed configuration explanations and default values please refer to the official documentation, where the key configuration is probably the following.

    • RUN_USERBy default git , specifies which user gogs to run
    • ROOTStorage root path for all warehouses
    • PROTOCOLIf you use the Nginx anti-generation, please use http , if the direct naked run to the external service, casual
    • DOMAINDomain name. Will affect the SSH clone address
    • ROOT_URLThe full root path affects the point at which the link on the page is accessed, and the address of the HTTP clone
    • HTTP_ADDRListen to the address, using Nginx suggestions 127.0.0.1 , otherwise 0.0.0.0 you can also
    • HTTP_PORTListening Port, default3000
    • INSTALL_LOCKLock the Installation page
    • Mailer related options

Mailer can use Mailgun's free mail delivery service to fill the Mailgun SMTP configuration into the configuration.

Nginx Anti-generation

/etc/nginx/sites-availableCreate a new file in, and write the following to the file.

server {    server_name domain name or IP;    Listen 80; # or 443, if you use HTTPS    # SSL on; whether to enable encrypted connection    # If you use HTTPS, you also need to fill in the Ssl_certificate and Ssl_certificate_key location    /{# If you want to access through a subpath, modify it here to a subpath, note the/start with/end        Proxy_pass http://127.0.0.1:3000/;    }}

Then enter /etc/nginx/sites-enabled , execute to ln -s ../sites-available/配置文件名 enable this configuration file.
Finally restart the nginx just fine, under Ubuntu is sudo service nginx restart .

Service scripts

The service script here is for the Debian system init script.

This section was revised on December 13, 2015 to amend the fact that changes occur over time.

when I write this article, the latest version of the service script seems to be a bit of a problem, you can use this version instead. the latest version of the service script is already working properly, please find the version in the binary download scripts folder that corresponds to your use of the release version. Put the script in the /etc/init.d file name gogs , give execution permissions and modify the parameters, you can use sudo service gogs start to start the service, or other sub-commands to easily manage.

Use Gogs to build your own Git server

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.