location problem with static content

Francis Daly francis at daoine.org
Wed Oct 30 18:47:52 UTC 2013

On Wed, Oct 30, 2013 at 11:15:42AM +0100, Philipp Kraus wrote:
> Am 29.10.2013 um 21:30 schrieb Francis Daly <francis at daoine.org>:
> > On Tue, Oct 29, 2013 at 07:34:15PM +0100, Philipp Kraus wrote:

Hi there,

There are a few possible different reasons for things not to be working
the way you want.

The best chance of getting things fixed if is there is clarity about
what was tried and failed.

The best information is of the form "I did A, I got B, but I expected
to get C".

> >>    location /gitlab {
> >>        root /home/gitlab/gitlab/public;
> >>        try_files $uri $uri/index.html $uri.html @gitlab;
> > 
> > I suspect that the "$uri/index.html" there may cause you problems. You
> > may be better off using "$uri/" instead.
> I have changed it to
>     location /gitlab {
>         alias /home/gitlab/gitlab/public;
>         try_files $uri/ @gitlab;
>     }

That's not what I intended to suggest you do.

  try_files $uri $uri/ $uri.html @gitlab;

where the $uri.html part is presumably gitlab-specific.

And "root" vs "alias" depends on what url to filename mapping you want to have.

> that does not work also.

So, next time, can you do something like

  curl -i http://server/gitlab

and see how what you get differs from what you expect to get?

What I'm guessing is that the file
/home/gitlab/gitlab/public/gitlab/index.html contains something
like <link href="static.css">. When you access the file via the
url http://server/gitlab, the browser follows the link and asks for
http://server/static.css -- which nginx expects to refer to the file

If you use the suggested try_files, then when you access
the url http://server/gitlab, you will be redirected to the
url http://server/gitlab/; when you access *that* url, you'll
get the same file content, but now the browser will ask for
http://server/gitlab/static.css, which nginx expects to refer to the
file /home/gitlab/gitlab/public/gitlab/static.css.

> > What url did you access to get this message?
> > 
> > What file on the filesystem did you want it to serve for that url?
> The message shows:
> 2013/10/30 11:10:18 [error] 6692#0: *5 open() "/home/www/static.css" failed (2: No such file or directory), client: <ip>, server: <server>,
> request: "GET /static.css HTTP/1.1", host: "<server>", referrer: "https://server/gitlab/profile/keys"

So, the url is /static.css.

nginx tries to return the file /home/www/static.css.

Which file on the filesystem do you want nginx to return, when it gets
a request for /static.css?

> I try to port this configuration https://github.com/gitlabhq/gitlabhq/blob/master/lib/support/nginx/gitlab
> to the subdirectory, so GitLab is not called on https://myserver/ but rather https://myserver/gitlab

>From the extra log line, I guess that perhaps the file
/home/gitlab/gitlab/public/gitlab/index.html contains instead something
like <link href="/static.css">. If that is the case, then the best
thing you can do if you want to proxy the application "gitlab" behind
the non-root-url /gitlab/, is to configure the application so that it
knows that its root url is /gitlab/, not /.

After you've done that, the nginx config should be simpler.

Good luck with it,

Francis Daly        francis at daoine.org

More information about the nginx mailing list