Welcome! Log In Create A New Profile

Advanced

Re: trouble with static content (Revised)

Francis Daly
November 07, 2021 10:08AM
On Sun, Nov 07, 2021 at 08:46:17AM -0500, deeztek wrote:

Hi there,

> So when I say static content, I mean resources such as .css, .js .png, .jpg
> etc.

Ok, so let's use one "js" request as an example here.

In nginx, one request is handled in one location. Only the config in,
or inherited into, that location, matters.

The nginx error log usually has useful information; when testing
things, it can be useful to set a more-than-usual logging level, as per
https://nginx.org/r/error_log

> so, with the following in place:
>
> location ~* .(?:ico|css|js|gif|jpe?g|png|woff2|map)$ {
> expires max;
> }
>
> Requests to the / location, I get 404s:
>
> GET https://host.domain.tld/static/js/vendor.d0bc79df.js net::ERR_ABORTED
> 404 (Not Found)
> GET https://host.domain.tld/static/css/index.393eb37d.css net::ERR_ABORTED
> 404 (Not Found)

What specific response do you want to get, to those requests?

The config above says that nginx should serve something like the file
/usr/local/nginx/html/static/js/vendor.d0bc79df.js in response to the
first request. The actual response is a 404. Does that file exist?

(The 404 response suggests that the file does not exist.)

(I say "something like", because your config does not show a "root"
that is in, or inherited into, the "location ~*" block that handles
this request. So the effective "root" value is whatever the compile-time
value was, which could be anything.)

So - what file on your filesystem do you want nginx to send you, when
you make the request for /static/js/vendor.d0bc79df.js?

If you want nginx to serve /var/www/html/static/js/vendor.d0bc79df.js,
then probably your best bet is to add "root /var/www/html;" at "server"
level, outside of all "location" blocks.

> However requests to the /admin location all work.

Again, for clarity: can you show one specific request that you make
("/admin/one.js", for example) and the response that you get ("http 200
and the contents of the file /var/www/html/admin/one.js" or "http 404",
for example).

> Also I forgot to add that the following:
>
> root /var/www/html;
>
> must also be present the server block before the /admin location works,
> which I think is odd because I have the:
>
> root /var/www/html/;
>
> in the /admin location.

Your "location /admin" has "proxy_pass", which means that "root" is
essentially ignored for every request that is handled in the /admin location.

If you have the "location ~*" block, then requests for "/admin/one.js"
are handled in that location, not in the /admin location -- so everything
in the /admin location is irrelevant for this request.

> Anyways, if I remove the following:
>
> location ~* .(?:ico|css|js|gif|jpe?g|png|woff2|map)$ {
> expires max;
> }
>
> Requests to the /admin location, I get 404s:
>
> GET https://192.168.10.145/admin/fusion.css net::ERR_ABORTED 404

If you remove that "location ~*", then a request for "/admin/fusion.css"
will be handled in your "location /admin" block, which means it will
be proxy_pass'ed to the upstream service on port 8888. It will not be
served by nginx from the filesystem.

The logs from your nginx server should show what response nginx got from
its upstream.

The logs from your port-8888 server should show why it sent that response
to nginx.

So the same question exists: what do you want nginx to do when it gets
the request for /admin/fusion.css?

Once you can write down what you want nginx to do with each request,
then it usually becomes easier to see how to tell nginx that you want
nginx to do that thing.

Good luck with it,

f
--
Francis Daly francis@daoine.org
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

trouble with static content (Revised)

deeztek November 07, 2021 07:01AM

Re: trouble with static content (Revised)

Francis Daly November 07, 2021 08:24AM

Re: trouble with static content (Revised)

deeztek November 07, 2021 08:46AM

Re: trouble with static content (Revised)

Francis Daly November 07, 2021 10:08AM

Re: trouble with static content (Revised)

deeztek November 07, 2021 11:00AM

Re: trouble with static content (Revised)

Francis Daly November 07, 2021 12:30PM

Re: trouble with static content (SOLVED)

deeztek November 08, 2021 06:56AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 258
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready