Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
240 lines (167 sloc) 5.84 KB
Detailed Config From Source

Detailed Configuration For Source Builds

Following the instruction of building from source, you should now have a local user git and a working setup of go and Gogs. We are going to setup Gogs along with Nginx. This way, we can take advantage of Nginx. This is useful for servers that already have an Nginx running.

For the rest fo this document, we'll assume the following:

  • You want to serve 'Gogs' on domain
  • Nginx is your webserver
  • postgresql is your database server
  • and you want your git repository URLs look like

As mentioned in Configuration and run, you should create your own configuration file in $GOPATH/src/

Let's first setup some directories:

sudo mkdir -p /var/log/gogs
sudo chown git:git /var/log/gogs
sudo su - git
cd ~
mkdir -p $GOPATH/src/
mkdir -p ~/gogs-repositories

Now copy the base configuration file so we can edit it:

cd $GOPATH/src/
cp conf/app.ini custom/conf/

Using your editor, open the configuration file:


for example:

vi $GOPATH/src/

Setting up server

Starting from top, change the following keys in different sections:

Default section


[repository] section


[server] section

HTTP_ADDR = localhost
HTTP_PORT = 3000

Setting up postgresql server

Under debian/ubuntu you can install it using:

sudo apt-get install -y postgresql postgresql-client libpq-dev

For OSX use brew:

brew install postgresql

Now let's setup database so our 'git' user can access it:

First login to psql:

# Login to PostgreSQL
sudo -u postgres psql -d template1

Then within psql prompt, enter:

# Create a user for git
# The following are typed in postgresql prompt

# Set up a password for git
# Remember this password for the next step
\password git

# Create the Gogs database & grant all privileges on database
CREATE DATABASE gogs_production OWNER git;

# Quit the database session

# Try connecting to the new database with the new user
sudo -u git -H psql -d gogs_production

# Quit the database session
gogs_production> \q

Now we can update app.ini, again open $GOPATH/src/ in your editor and change the following (make sure you are the user git, if not enter sudo su - git):

[database] section

DB_TYPE = postgres
NAME = gogs_production
USER = git
PASSWD =__postgresql_password_used_in_previous_step__
PATH = data/gogs.db

Setting up Nginx sever

Under debian/ubuntu you can install it using:

sudo apt-get install -y nginx

Now let's create an Nginx config file for our Gogs:

sudo su - git
# Use your editor to create a temp file:
vi /tmp/gogs

And add the following to it:

server {
    listen 80;

    location / {
        proxy_pass http://localhost:3000;

Now add this file to Nginx and restart it:

sudo mv /tmp/gogs /etc/nginx/sites-available/
sudo ln -s /etc/nginx/sites-available/gogs /etc/nginx/sites-enabled/gogs
sudo service nginx restart

and then:

sudo su - git
cd $GOPATH/src/
./gogs web

Using your browser, you should be able to visit

Of course if you have not already done the initial setup, you will be presented with a screen like this:

installation page screenshot

Change the Database Type to PostgreSQL if it's not already selected. After verifying that other settings match to what you have entered in your custom app.ini file, click install and enjoy your new git web app!

You are basically done here, the next step outlines how to make Gogs start when debian/ubuntu is restarted.

Adding Gogs to init.d

This section describes how to properly start Gogs when your linux system reboots. For other platforms, consult the documentation to see how you can do this. For Mac OSX see this document to control app start-ups.

If you followed previous steps, you can now enable automatic start of gogs. Under debian/ubuntu, we will use the script from $GOPATH/src/

Let's copy the script and modify it:

# change to 'git' user
sudo su - git
cd ~
cp $GOPATH/src/ ./gogs.init

Using your editor open ~/gogs.init and modify it such as:

  • Change these two lines at the top of file:
# Required-Start:    $syslog $network
# Required-Stop:     $syslog


# Required-Start:    $syslog $network $local_fs nginx postgresql
# Required-Stop:     $syslog $local_fs

Further down in the same file, set the location so init.d can find our gogs installation by changing WORKING_DIR line to:


Move the file to /etc/init.d and update it:

# firt change user to normal account if you haven't already
# move the files and update the system
sudo mv /home/git/gogs.init /etc/init.d/gogs
sudo chmod ug+x /etc/init.d/gogs
sudo update-rc.d gogs defaults 30 70

Test your setup by running

sudo service gogs start

and visiting the URL for your site (ex.

If you want to autostart gogs using systemd, check out the related FAQ.