Welcome! Log In Create A New Profile

Advanced

Re: django app static files on the different server not get loaded

Francis Daly
January 03, 2022 05:54AM
On Sun, Jan 02, 2022 at 04:26:40PM -0500, ningja wrote:

Hi there,

> The issue is I need to configure nginx1 to allow people to access app2 from
> the public internet. The config file I post here is from test1 server.
> With this config I can access app2 html pages from the internet (just what I
> wanted) but the page did NOT try load the static files from
> https://test2.com/app2/ instead it try to load the static from
> https://test1.com/app2/. How can I have the nginx to look app2's static
> files under https://test2.com?

You need your nginx to know that a request for /static/img/for-app1.jpg
should be handled by reading from the local filesystem; and that a request
for /static/img/for-app2.jpg should be handled by doing a proxy_pass
to https://test2.com.

There is no (reliable) part of the request that nginx gets, that will
let nginx know that this request "came from" app1 while that request
"came from" app2. The only thing you have is the url.

If you want to keep both sets of images under the url prefix /static/, and
you are unable to write a "location" pattern that will match all-and-only
the images from one of the apps, then you probably need to enumerate
the urls that correspond to one of the apps.

One possible way to do this could be to keep your "location /static/"
reading from the local filesystem (so: defaults to app1); and add a set
of other locations of the form

location = /static/img/logo-2.jpg { proxy_pass https://test2.com:444; }

I suspect it would be simpler if the app2-static files were below
"/static2/", or below "/app2/static/"; but it's your system and you get
to choose how to set it up.

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

django app static files on the different server not get loaded

ningja December 31, 2021 05:45PM

Re: django app static files on the different server not get loaded

Francis Daly January 02, 2022 07:54AM

Re: django app static files on the different server not get loaded

ningja January 02, 2022 04:26PM

Re: django app static files on the different server not get loaded

Paul January 02, 2022 06:34PM

Re: django app static files on the different server not get loaded

ningja January 02, 2022 08:56PM

Re: django app static files on the different server not get loaded

ningja January 03, 2022 08:52AM

Re: django app static files on the different server not get loaded

Francis Daly January 03, 2022 05:54AM

Re: django app static files on the different server not get loaded

ningja January 03, 2022 08:49AM

Re: django app static files on the different server not get loaded

ningja January 03, 2022 09:59AM

Re: django app static files on the different server not get loaded

ningja January 03, 2022 05:58PM

Re: django app static files on the different server not get loaded

Francis Daly January 05, 2022 10:52AM

Re: django app static files on the different server not get loaded

ningja January 05, 2022 11:36AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 296
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