Reverse proxing gitbucket via nginx

1

I'm currently trying to make nginx work with gitbucket using following this tutorial.

Although this is the official gitbucket wiki this page is very incomplete, and i need to adapt some details from the guide for apache, mainly the prefix thing, to make gitbucket work with nginx.

So my resulting sites-available/gitbucket is here:

server {
    listen   80; # The default is 80 but this here if you want to change it.
    server_name mydomain.xxx;

    location /gitbucket {
        proxy_pass              http://localhost:8080/gitbucket;
        proxy_set_header        Host $host;
        proxy_set_header        X-Real-IP $remote_addr;
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_connect_timeout   150;
        proxy_send_timeout      100;
        proxy_read_timeout      100;
        proxy_buffers           4 32k;
        client_max_body_size    500m; # Big number is we can post big commits.
        client_body_buffer_size 128k;
    }
}

When i enable gitbucket it works, so http://mydomain.xxx/gitbucket redirects to my gitbucket instance, but then nginx stop serving any index file i put on my /var/www/html, and instead serves the default index page supplied when we fresh install it. And when disabling gitbucket the index from html folder is served again.

I've tried to make a ticket on gitbucket repo but i didn't get any satisfactory reply. So can someone shed me light on this problem?

Thanks in advance!

Vico

Posted 2018-07-06T05:02:22.280

Reputation: 241

Make sure your sites-enabled are read in the correct order. – Seth – 2018-07-06T05:21:20.843

Sorry, i didnt understand what you mean with "correct order". I'm a bit newbie on nginx (always used apache). – Vico – 2018-07-06T06:21:39.433

You likely still have more than one file in sites-enabled check the content of that file. Currently you're telling nginx to respond with a block that only defines /gitbucket. Have a look at this Digital Ocean Article: Understanding Nginx Server and Location Block Selection Algorithms

– Seth – 2018-07-06T08:09:53.423

I have. gitbucket (ive created) and default (the one shipped with nginx). But the wiki leaves implicit i need to create a separated sites-enabled file to deal with gitbucket. – Vico – 2018-07-06T20:39:53.817

1No. It's an example but you don't need to have a separate file. You can easily put the location block in your default file or vice versa. You're not able to have two files with the same listen and server name directive. One will always have precedence. – Seth – 2018-07-09T05:29:56.607

Ok, adding only the location... part of the snippet on default worked for me. – Vico – 2018-07-09T14:44:01.633

Answers

1

The tutorial you linked gives a very specific example for gitbucket.

If you're setting up sites using nginx you will have to keep in mind that each site has a bunch of settings and that there is a logic that will determine what takes precedence when. This digital ocean article titled "Understanding Nginx Server and Location Block Selection Algorithms" about how that's determined.

From what you explained in your comments you ended up with two site files. One being the default file where you set your regular root for your site and one for gitbucket that just contained the gitbucket location block and (that's is important) a listen directive and server name directive.

The first step nginx takes to determine which site to deliver is to figure out what server block to use. As it currently is you likely have two server blocks with the same definition. Your default and gitbucket block are listening to port 80 for the same server name. So one is always going to be overwriting the other.

If you want both to work you have a few options:

  • Set either site to a different port using the listen directive.
  • Change the server name for either site. This could also include a sub domain. Whenever this works or not might be dependend on the DNS configuration for the site.
  • Just include the location block from your gitbucket configuration in your default file.

A location block, as the name implies, just defines settings for a very specific location. It doesn't really need an independent server block, at least not if it's such a basic definition.

Seth

Posted 2018-07-06T05:02:22.280

Reputation: 7 657

1Yes! That's what i did: Just included the location in default. Thanks for formalize that! – Vico – 2018-07-10T20:15:27.267