Installation instructions break NGINX default virtual host config
Created by: mcdelorme
Hello,
I've installed Gitlab on Ubuntu 10.04 as per the installtion instructions here:
https://github.com/gitlabhq/gitlabhq/blob/stable/doc/installation.md
The nginx config that is presented in the installation instructions does not allow for the nginx server to serve up the Gitlab application under the following circumstances:
- An alternate hostname is used to access Gitlab (e.g. using the IP address of the machine directly)
- An alternate port is used to access Gitlab (e.g. port forwarding on a home router that uses NAT)
In essence, the provided config breaks nginx's ability to serve up Gitlab as the default host. What winds up happening is the URL gets rewritten to the literal that is provided in the server_name
field. Consider the provided nginx config:
upstream gitlab {
server unix:/tmp/gitlab.socket;
}
server {
listen 80;
server_name mygitlab.com;
location / {
root /home/gitlab/gitlab/public;
if (!-f $request_filename) {
proxy_pass http://gitlab;
break;
}
}
}
This config is set up to respond to the virtual hostname mygitlab.com
. Unfortunately, this does not allow us to access Gitlab unless we use this URL/port combination. To get around this, nginx allows us to specify this server as the default server as follows:
upstream gitlab {
server unix:/tmp/gitlab.socket;
}
server {
listen 80 default;
server_name _;
location / {
root /home/gitlab/gitlab/public;
if (!-f $request_filename) {
proxy_pass http://gitlab;
break;
}
}
}
Using the default
directive in combination with _
as the server name works in the general case as per the nginx documentation. Unfortunately, when we use the above config and try to navigate to Gitlab in a browser, the URL gets rewritten to use the literal _
as the base URL string and we get redirected to http://_/users/sign_in:80
. I looked into this further, and the reason for this is the following stub:
if (!-f $request_filename) {
proxy_pass http://gitlab;
break;
}
Specifically, the proxy_pass http://gitlab;
statement is breaking things. If we remove this from the nginx config, then nginx does not redirect the browser to http://_/users/sign_in
anymore. Unfortunately, however, Gitlab is still not served up and instead we get a 403: Forbidden
page.
In summary, the provided Gitlab instructions do not allow for Gitlab to act as the default virtual host for nginx. Attempting to do so using the nginx documentation doesn't work because the `proxy_pass http://gitlab;' statement causes the client web browser to go to a (potentially) invalid URL/port. This makes Gitlab unsuitable for use in many environments.