Linux Tactic

Streamline Git Hosting: Install and Upgrade Gogs with Nginx

How to Install and Configure Gogs with Nginx as SSL Termination Proxy

Are you looking for a way to manage your Git repositories privately and securely? Gogs is a popular Git web hosting service that provides fast and easy Git server setup.

In this article, we will explore how to install and configure Gogs with Nginx as SSL Termination Proxy.

Installation of Gogs

The first step to using Gogs is to install Git. Git is an open-source version control system that is used to manage source code changes.

Installing Git can be done through your Linux distribution’s package manager. Once Git is installed, create a system user for Gogs.

You can do this by running the command:

“`

sudo adduser –system –group –disabled-password –shell /bin/bash git

“`

Next, download the Gogs binary from their official website. Choose the appropriate binary for your server architecture and extract it to the /home/git/gogs directory.

Now, create a systemd unit file to manage the Gogs service. Create a file called /etc/systemd/system/gogs.service with the following contents:

“`

[Unit]

Description=Gogs

After=syslog.target

After=network.target

[Service]

User=git

Group=git

WorkingDirectory=/home/git/gogs/

ExecStart=/home/git/gogs/gogs web

Restart=always

Environment=USER=git HOME=/home/git GOGS_CUSTOM=/home/git/gogs/custom

[Install]

WantedBy=multi-user.target

“`

After you’ve saved the file, run the following commands to start and enable the Gogs service:

“`

sudo systemctl start gogs

sudo systemctl enable gogs

“`

Installing Gogs Using the Web Installer

To install Gogs using the web installer, you will need to access the Gogs service through a web browser. Navigate to your server’s domain or IP address using https:// in your browser.

You should see the Gogs installation page. Follow the instructions on the page to configure database settings, application settings and create an admin account.

Configuring Nginx as SSL Termination Proxy

The next step is to configure Nginx to act as an SSL Termination Proxy for your Gogs service. First, install Nginx and the Certbot tool that is used to issue Let’s Encrypt SSL certificates.

On Ubuntu, you can do this by running these commands:

“`

sudo apt install nginx certbot python3-certbot-nginx

“`

After installation, update the Nginx configuration file at /etc/nginx/sites-available/default to include the following:

“`

server {

listen 80;

server_name gogs.example.com;

location / {

return 301 https://$server_name$request_uri;

}

}

server {

listen 443 ssl http2;

server_name gogs.example.com;

ssl_certificate /etc/letsencrypt/live/gogs.example.com/fullchain.pem;

ssl_certificate_key /etc/letsencrypt/live/gogs.example.com/privkey.pem;

ssl_trusted_certificate /etc/letsencrypt/live/gogs.example.com/chain.pem;

location / {

proxy_set_header Host $host;

proxy_set_header X-Real-IP $remote_addr;

proxy_pass http://localhost:3000;

}

}

“`

This configuration will redirect all HTTP traffic to HTTPS and proxy all requests to your Gogs installation. Make sure to update the server_name variable with your server’s domain.

After updating the configuration, test it with the following command:

“`

sudo nginx -t

“`

If the test passes, reload Nginx with the following command:

“`

sudo systemctl reload nginx

“`

Changing Gogs Domain and Root URL

Now that Nginx is configured, you need to update the Gogs configuration file located at /home/git/gogs/custom/conf/app.ini. Update the domain and root URL values to match your server’s domain.

The file should have the following entries:

“`

[server]

DOMAIN = gogs.example.com

ROOT_URL = https://gogs.example.com/

“`

Service Restart

Finally, restart the Gogs service to apply the configuration changes with this command:

“`

sudo systemctl restart gogs

“`

Conclusion

In this article, we explored how to install and configure Gogs with Nginx as SSL Termination Proxy. By following these steps, you can set up a Git hosting service that is both fast and secure.

With Gogs, you can securely manage your code repositories and easily collaborate with your team.

Upgrading Gogs

Gogs is an excellent tool for Git repository hosting and management that allows for fast and efficient handling of Git-based projects. Once you’ve installed Gogs, you’ll want to upgrade it to the latest version to take advantage of new features and security updates.

In this article, we’ll provide you with a step-by-step guide on how to upgrade Gogs.

Stopping the Gogs Service

The first step to upgrading Gogs is to stop the Gogs service. This is important as the update process may require overwriting configuration files or other system data, which can cause data loss or corruption if interrupted or incomplete.

To stop the Gogs service, run the following command on your terminal:

“`

sudo systemctl stop gogs

“`

Renaming the Gogs Installation Directory

The next step is to rename the old Gogs installation directory to something else. This ensures that the new version will have a distinct installation path and prevent any conflicts between the old and new versions.

To rename the directory, run the following command:

“`

sudo mv /home/git/gogs /home/git/gogs-old

“`

Downloading and Moving the Latest Gogs Version

Now it’s time to download and move the latest Gogs version to your server. You can download it from the official Gogs website.

Choose the appropriate binary for your server architecture, and extract it to a new folder under the Gogs installation’s parent folder. Here’s an example:

“`

cd /home/git

sudo tar xzvf /path/to/gogs_0.12.3_linux_amd64.tar.gz

sudo mv gogs /home/git/

“`

Copying Custom, Data, and Log Directories to the Extracted Directory

Next, copy any custom directory, data directory, and log directory from your old Gogs installation directory to the newly extracted directory of the upgraded Gogs.

Please make sure to copy the directory’s contents only rather than the directory itself. Here’s an example:

“`

sudo cp -rp /home/git/gogs-old/custom /home/git/gogs/

sudo cp -rp /home/git/gogs-old/data /home/git/gogs/

sudo cp -rp /home/git/gogs-old/log /home/git/gogs/

“`

Starting the Gogs Service

Finally, it’s time to start the Gogs service and test the upgraded version. Before starting the service, edit the app.ini file in the new Gogs installation directory and update the domain and root URL values to the correct ones.

Once done, start the Gogs service with the following command:

“`

sudo systemctl start gogs

“`

If everything is working correctly, you should be able to log in to your upgraded Gogs instance and see all your repositories and settings.

Conclusion

In this article, we covered how to upgrade Gogs to the latest version. By following these steps, you can keep Gogs up-to-date while ensuring that your data and configuration are safe.

Always make sure to take backups of your data before upgrading, and double-check that everything is working correctly after the upgrade is complete. With Gogs, you have an excellent Git hosting solution that is reliable, secure and easy to manage.

In this article, we covered two important topics related to Gogs installation and management: how to install and configure Gogs with Nginx as SSL Termination Proxy, and how to upgrade Gogs to the latest version. By following the step-by-step guide, you can install, manage, and upgrade Gogs easily and securely, ensuring that your Git repositories are always up-to-date and safe.

The takeaway here is that Gogs is an excellent Git hosting solution that is reliable, secure, and easy to manage, with the added advantage of being open-source. Whether you’re starting a new project or managing a large team, Gogs is an excellent tool to use.

Popular Posts