Help for nginx proxy pass rule

HI,

We have a WordPress site named it as https://www.abc.com; We are using
Nginx
as the web server for this site. I wanted to create a proxy pass rule
like
this

https://www.abc.com/static/js/widget.js will be load from
https://www.xys.org/static/js/widget.js without changing URL

Here is the configuration that I configured for this requirement in the
www.abc.com Nginx site configuration file

location /static {

    proxy_pass      https://www.xys.org/static;

    proxy_set_header Host  www.xys.org;

    proxy_set_header X-Real-IP $remote_addr;

    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

    proxy_set_header X-Forwarded-Proto $scheme;

}

When I access https://www.abc.com/static/js/widget.js, I am getting
Nginx
404 Not Found error with the following error log in its log file

2016/04/06 06:39:14 [error] 20107#0: *907 open()
“/usr/share/nginx/html/www.abc.com/static/js/widget.js” failed (2: No
such
file or directory), client: 118.102.223.138, server: www.abc.com,
request:
“GET /static/js/widget.js HTTP/1.1”, host: www.abc.com

I have tried different Nginx proxy pass configuration but not success
yet.
It will be good to get your thought to fix this issues

Thanks

Roni

Are you sure the location is working?

abc.com/static/js/widget.js" failed (2: No such file or directory) - I
think its trying to access that file locally and not via the proxy

On Wed, Apr 6, 2016 at 4:14 PM, Roni B. [email protected]
wrote:

https://www.abc.com/static/js/widget.js will be load from

}


nginx mailing list
[email protected]
http://mailman.nginx.org/mailman/listinfo/nginx


Anoop P Alias

Yes the destination URl [https://www.xys.org/static/js/widget.js] is
working
perfectly alone
Why it tried locally? I used proxypass rule for it. If I wanted to do
anything to enable proxy capability in my Nginx?

Thanks for your reply
Roni

On Wed, Apr 06, 2016 at 06:58:07PM +0530, Roni B. wrote:

Hi there,

Yes the destination URl [https://www.xys.org/static/js/widget.js] is working
perfectly alone
Why it tried locally? I used proxypass rule for it. If I wanted to do
anything to enable proxy capability in my Nginx?

Read http://nginx.org/r/location

Then do something like

grep location your.conf

to see which location{} blocks you have defined.

Which one of those locations will nginx use to handle this request?

The error log suggests that this request is handled in a location that
is not the one that you showed – perhaps one defined as something like

location ~ js$ {

Possibly changing your

location /static {

to

location ^~ /static {

will make it work the way you want. That would tell nginx to choose it
instead of any regex one, for this request.

Separate from that: for the proxy_pass directive, you could probably
drop
the “/static” part of the argument since it matches the request prefix.

But until the proxy_pass is actually used, changing it will make no
difference.

f

Francis D. [email protected]

Perfect fix… Able to solve my issues.Thanks Francis

The issue was, I configured these location blocks already in my config
file

location ~* ^.+.(jpg|jpeg|gif|css|png|ico|zip|xspf|swf|ttf|woff|js)$ {
for
serving static files directly.

It was over ride the location rule that I used

It started to work my location rule changed it like this as per your
recommendation

location ^~ /static {

Thanks a Lot
Roni B.

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