To prepare

  • Centos7 64
  • nginx
  • git
  • Mysql /PostgreSQL/MSSQL (optional)

start

Create and switch git users

adduser git
passwd git # Input password
su git
Copy the code

Download the Gogs level 2 package

Visit the official website to download the latest compiled binary package, I think this is the most convenient way to save trouble.

Wget http://7d9nal.com2.z0.glb.qiniucdn.com/0.11.34/linux_amd64.tar.gz tar ZXVF linux_amd64. Tar. Gzcd gogs
./gogs web -port 10086 If the port is not specified, use the default 80
Copy the code

Initial Configuration

Browser to the previous boot address: http://localhost:10086/

instructions

  1. Database I choose the lightweight database SQLite3 of the application, which can be selected according to the actual situation
  2. If you want to go live, change the localhost section to your domain name
  3. Mail service I choose gmail SMTP send service, conditional can use their own mail server
  4. If you want to modify the configuration by clicking Install Now, you can modify the user profile./custom/conf/app.iniRestart the application

Background processes

nohup ./gogs web >> /your/path/to/save/nohup.out 2>&1 &
Copy the code

At this point, you’ve basically set up Gogs, so stop there if you want to use it on a LOCAL network, but keep reading if you want to deploy it online.

Deployment of the network

Assuming you have configured DNS resolution.

Binding domain

Run vi./custom/conf/app.ini to find the content of [server] :

[server]
DOMAIN           = gitfan.club
HTTP_PORT        = 10086
ROOT_URL         = http://gitfan.club/
DISABLE_SSH      = false
SSH_PORT         = 22
START_SSH_SERVER = true
OFFLINE_MODE     = false
Copy the code

Nginx configuration

Add the gitfan. Conf file to /etc/nginx/conf.d/ and configure the following:

server {
    server_name gitfan.club;
    listen 80;

    client_max_body_size 5G; # Break the limit of uploading large files

    location / {
        proxy_pass http://localhost:10086;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-Forwarded-Proto $scheme; proxy_buffering off; }}Copy the code

Then start nginx:

systemctl start nginx.service
Copy the code

Access is available at this point.

Deploying the Upgrade

Support HTTPS

We all know that HTTPS is the inevitable, and now we’re going to upgrade our site to HTTPS. I use the free DV certificate service Let’s Encrypt, which is valid for 3 months and needs to be renewed after expiration.

To get the certificate

git clone https://github.com/certbot/certbot.git
cd certbot
chmod +x letsencrypt-auto
./letsencrypt-auto certonly --webroot -w /home/git/gogs/public -d gitfan.club
Copy the code

At this point, the generated certificate stored in the/etc/letsencrypt/live/gitfan club /, then configure nginx listening on port 443.

# /etc/nginx/conf.d/gitfan.conf
server {
    server_name gitfan.club;
    listen 443;
    ssl on;
    ssl_certificate /etc/letsencrypt/live/gitfan.club/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/gitfan.club/privkey.pem;

    client_max_body_size 5G;

    location / {
        proxy_pass http://localhost:10086;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-Forwarded-Proto $scheme; proxy_buffering off; }}Copy the code

If you want to force HTTPS for both www.gitfan.club and gitfans. club, add the following configuration to the gitfans. conf file:

server {
    listen      80;
    server_name gitfan.club www.gitfan.club;
    return      301         https://gitfan.club$request_uri;
}
Copy the code

Setting a Firewall

You may also need to configure the firewall to increase server security. The firewall-cmd of centos supports the configuration of open ports:

systemctl start firewalld.service firewall-cmd --permanent --add-port=443/tcp firewall-cmd --permanent --add-port=80/tcp  firewall-cmd --reload firewall-cmd --list-portsCheck whether the port is set successfully
Copy the code

Other problems

  1. What if I want to modify the page template?

    A: See here to add a template file in Custom /templates/ Inject /.

  2. What if I want to stop the Gogs service?

    A: ps – ef | grep gogs find the process ID, and then kill 9 process ID.