Location problem with static content

Hello,

I have created for my GitLab installation this entries in the
configuration:

location /gitlab {
    root /home/gitlab/gitlab/public;
    try_files $uri $uri/index.html $uri.html @gitlab;
}

location @gitlab {
    proxy_read_timeout      300;
    proxy_connect_timeout   300;
    proxy_redirect          off;
    proxy_set_header        X-Forwarded-Proto $scheme;
    proxy_set_header        Host $http_host;
    proxy_set_header        X-Real-IP $remote_addr;

    proxy_pass             http://localhost:9080;
}

so I can use GitLab with https://myserver/gitlab, most functions of
GitLab works well, but I have got a problem with the static content.
I get this error:

[error] 4573#0: *4 open() “/home/www/static.css” failed (2: No such file
or directory)

The message is correct, because the main root dir (above the location)
is set to /home/www, so the fallback mechanism works.
But in my case I need a correct rule, that also static content, which
have got the /gitlab URL part are mapped into /home/gitlab/gitlab/public

How can I tell my location rule, that static content is stored in the
correct root folder?

Thanks

Phil

On Tue, Oct 29, 2013 at 07:34:15PM +0100, Philipp Kraus wrote:

Hi there,

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 get this error:

[error] 4573#0: *4 open() “/home/www/static.css” failed (2: No such file or
directory)

What url did you access to get this message?

What file on the filesystem did you want it to serve for that url?

How can I tell my location rule, that static content is stored in the correct
root folder?

You may need to use “alias” rather than “root”; but that should become
clear when you describe the url -> filename mapping that you want.

f

Francis D. [email protected]

Am 29.10.2013 um 21:30 schrieb Francis D. [email protected]:

On Tue, Oct 29, 2013 at 07:34:15PM +0100, Philipp Kraus wrote:

Hi there,

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 does not work also. I have tested it with the “try_files $uri
$uri.css”.

I get this error:

[error] 4573#0: *4 open() “/home/www/static.css” failed (2: No such file or
directory)

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: , server: ,
request: “GET /static.css HTTP/1.1”, host: “”, referrer:
https://server/gitlab/profile/keys

How can I tell my location rule, that static content is stored in the correct
root folder?

You may need to use “alias” rather than “root”; but that should become
clear when you describe the url -> filename mapping that you want.

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

Thanks for help

Phil

On Wed, Oct 30, 2013 at 11:15:42AM +0100, Philipp Kraus wrote:

Am 29.10.2013 um 21:30 schrieb Francis D. [email protected]:

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”.

    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 . 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
/home/www/static.css.

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: , server: ,
request: “GET /static.css HTTP/1.1”, host: “”, 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 . 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,

f

Francis D. [email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs