# Help for nginx proxy pass rule

**URL:** <https://www.ruby-forum.com/t/help-for-nginx-proxy-pass-rule/244412>\
**Category:** NGINX\
**Created:** [April 6, 2016, 12:45pm UTC](https://www.ruby-forum.com/t/help-for-nginx-proxy-pass-rule/244412 "2016-04-06T12:45:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sadaf\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@Sadaf\_N](https://www.ruby-forum.com/u/Sadaf_N)\
**Post date:** [April 6, 2016, 12:45pm UTC](https://www.ruby-forum.com/t/help-for-nginx-proxy-pass-rule/244412/1 "2016-04-06T12:45:23Z")

</div>

HI,

We have a WordPress site named it as [https://www.abc.com](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](https://www.abc.com/static/js/widget.js) will be load from  
[https://www.xys.org/static/js/widget.js](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](http://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](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](http://www.abc.com),  
request:  
“GET /static/js/widget.js HTTP/1.1”, host: [www.abc.com](http://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

---

<div class="post-metadata">

**Author:** ![Roni\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/82dd89/32.png) [@Roni\_B](https://www.ruby-forum.com/u/Roni_B)\
**Post date:** [April 6, 2016, 3:21pm UTC](https://www.ruby-forum.com/t/help-for-nginx-proxy-pass-rule/244412/2 "2016-04-06T15:21:57Z")

</div>

Are you sure the location is working?

[abc.com/static/js/widget.js](http://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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> [https://www.abc.com/static/js/widget.js](https://www.abc.com/static/js/widget.js) will be load from
> 
> }
> 
> * * *
> 
> nginx mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [mailman.nginx.org archive](http://mailman.nginx.org/mailman/listinfo/nginx)

–  
Anoop P Alias

---

<div class="post-metadata">

**Author:** ![Roni\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/82dd89/32.png) [@Roni\_B](https://www.ruby-forum.com/u/Roni_B)\
**Post date:** [April 6, 2016, 3:28pm UTC](https://www.ruby-forum.com/t/help-for-nginx-proxy-pass-rule/244412/3 "2016-04-06T15:28:58Z")

</div>

Yes the destination URl [[https://www.xys.org/static/js/widget.js](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

---

<div class="post-metadata">

**Author:** ![Roni\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/82dd89/32.png) [@Roni\_B](https://www.ruby-forum.com/u/Roni_B)\
**Post date:** [April 6, 2016, 11:47pm UTC](https://www.ruby-forum.com/t/help-for-nginx-proxy-pass-rule/244412/4 "2016-04-06T23:47:16Z")

</div>

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](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 [Module ngx\_http\_core\_module](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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Roni\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/82dd89/32.png) [@Roni\_B](https://www.ruby-forum.com/u/Roni_B)\
**Post date:** [April 7, 2016, 6:20am UTC](https://www.ruby-forum.com/t/help-for-nginx-proxy-pass-rule/244412/5 "2016-04-07T06:20:25Z")

</div>

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.
