Welcome! Log In Create A New Profile

Advanced

Using the mirror module

Posted by Kenny Meyer 
Kenny Meyer
Using the mirror module
March 13, 2018 09:40PM
Hi,

I’m having trouble using the new mirror module. I want to mirror incoming requests from Nginx to other upstream servers. 1) a production server 2) a staging server

This is my config:

server {
listen 80 default_server;
listen [::]:80 default_server;

location / {
mirror /mirror;
proxy_pass http://www.example.com;
}

location /mirror {
internal;
proxy_pass http://staging.example.com$request_uri;
}
}

So, I request http://myserver.com (where Nginx is hosted) and it successfully redirects me to www.example.com, however I don’t see any requests hitting staging.example.com.

What could be the error?
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Roman Arutyunyan
Re: Using the mirror module
March 13, 2018 10:40PM
Hi Kenny,

On Tue, Mar 13, 2018 at 05:37:52PM -0300, Kenny Meyer wrote:
> Hi,
>
> I’m having trouble using the new mirror module. I want to mirror incoming requests from Nginx to other upstream servers. 1) a production server 2) a staging server
>
> This is my config:
>
> server {
> listen 80 default_server;
> listen [::]:80 default_server;
>
> location / {
> mirror /mirror;
> proxy_pass http://www.example.com;
> }
>
> location /mirror {
> internal;
> proxy_pass http://staging.example.com$request_uri;
> }
> }
>
> So, I request http://myserver.com (where Nginx is hosted) and it successfully redirects me to www.example.com, however I don’t see any requests hitting staging.example.com.
>
> What could be the error?

The configuration looks fine.
Are there any errors in error.log?
And what happens if you switch www.example.com and staging.example.com?

--
Roman Arutyunyan
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Kenny Meyer
Re: Using the mirror module
March 13, 2018 11:10PM
Hi Roman,

> Are there any errors in error.log?
No errors…

> And what happens if you switch www.example.com and staging.example.com?
Then I get redirected to staging.example.com and I don’t see any requests being logged on example.com



> On 13 Mar, 2018, at 18:34, Roman Arutyunyan <[email protected]> wrote:
>
> Hi Kenny,
>
> On Tue, Mar 13, 2018 at 05:37:52PM -0300, Kenny Meyer wrote:
>> Hi,
>>
>> I’m having trouble using the new mirror module. I want to mirror incoming requests from Nginx to other upstream servers. 1) a production server 2) a staging server
>>
>> This is my config:
>>
>> server {
>> listen 80 default_server;
>> listen [::]:80 default_server;
>>
>> location / {
>> mirror /mirror;
>> proxy_pass http://www.example.com;
>> }
>>
>> location /mirror {
>> internal;
>> proxy_pass http://staging.example.com$request_uri;
>> }
>> }
>>
>> So, I request http://myserver.com (where Nginx is hosted) and it successfully redirects me to www.example.com, however I don’t see any requests hitting staging.example.com.
>>
>> What could be the error?
>
> The configuration looks fine.
> Are there any errors in error.log?
> And what happens if you switch www.example.com and staging.example.com?
>
> --
> Roman Arutyunyan
> _______________________________________________
> nginx mailing list
> nginx@nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx

Kenny Meyer
www.kennymeyer.net

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Peter Booth
Re: Using the mirror module
March 13, 2018 11:40PM
This is the point where I would jump to using the debug log. You need to build you nginx binary
with —with-debug switch and change the log level to debug innginx.conf. Debug generates a *huge*
amount of logs but it really is invaluable.

I would also want to double check what is actually happening and use ss or tcpdump
to confirm that no request is sent to your staging destination.

I’m assuming that both ww.example.com and staging.example.com are hosted
on different hosts, different IPs and are both functional.

Peter



> On Mar 13, 2018, at 5:58 PM, Kenny Meyer <[email protected]> wrote:
>
> Hi Roman,
>
>> Are there any errors in error.log?
> No errors…
>
>> And what happens if you switch www.example.com and staging.example.com?
> Then I get redirected to staging.example.com and I don’t see any requests being logged on example.com
>
>
>
>> On 13 Mar, 2018, at 18:34, Roman Arutyunyan <[email protected]> wrote:
>>
>> Hi Kenny,
>>
>> On Tue, Mar 13, 2018 at 05:37:52PM -0300, Kenny Meyer wrote:
>>> Hi,
>>>
>>> I’m having trouble using the new mirror module. I want to mirror incoming requests from Nginx to other upstream servers. 1) a production server 2) a staging server
>>>
>>> This is my config:
>>>
>>> server {
>>> listen 80 default_server;
>>> listen [::]:80 default_server;
>>>
>>> location / {
>>> mirror /mirror;
>>> proxy_pass http://www.example.com;
>>> }
>>>
>>> location /mirror {
>>> internal;
>>> proxy_pass http://staging.example.com$request_uri;
>>> }
>>> }
>>>
>>> So, I request http://myserver.com (where Nginx is hosted) and it successfully redirects me to www.example.com, however I don’t see any requests hitting staging.example.com.
>>>
>>> What could be the error?
>>
>> The configuration looks fine.
>> Are there any errors in error.log?
>> And what happens if you switch www.example.com and staging.example.com?
>>
>> --
>> Roman Arutyunyan
>> _______________________________________________
>> nginx mailing list
>> nginx@nginx.org
>> http://mailman.nginx.org/mailman/listinfo/nginx
>
> Kenny Meyer
> www.kennymeyer.net
>
> _______________________________________________
> nginx mailing list
> nginx@nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Roman Arutyunyan
Re: Using the mirror module
March 13, 2018 11:40PM
On Tue, Mar 13, 2018 at 06:58:25PM -0300, Kenny Meyer wrote:
> Hi Roman,
>
> > Are there any errors in error.log?
> No errors…
>
> > And what happens if you switch www.example.com and staging.example.com?
> Then I get redirected to staging.example.com and I don’t see any requests being logged on example.com

Do you have a resolver defined in the http{} block?
Proxying to "http://staging.example.com$request_uri"; requires a resolver.
Normally, you would have "no resolver defined to resolve ..."
error logged if resolver is missing, but you may not see it if, for example,
your log level is too high.

> > On 13 Mar, 2018, at 18:34, Roman Arutyunyan <[email protected]> wrote:
> >
> > Hi Kenny,
> >
> > On Tue, Mar 13, 2018 at 05:37:52PM -0300, Kenny Meyer wrote:
> >> Hi,
> >>
> >> I’m having trouble using the new mirror module. I want to mirror incoming requests from Nginx to other upstream servers. 1) a production server 2) a staging server
> >>
> >> This is my config:
> >>
> >> server {
> >> listen 80 default_server;
> >> listen [::]:80 default_server;
> >>
> >> location / {
> >> mirror /mirror;
> >> proxy_pass http://www.example.com;
> >> }
> >>
> >> location /mirror {
> >> internal;
> >> proxy_pass http://staging.example.com$request_uri;
> >> }
> >> }
> >>
> >> So, I request http://myserver.com (where Nginx is hosted) and it successfully redirects me to www.example.com, however I don’t see any requests hitting staging.example.com.
> >>
> >> What could be the error?
> >
> > The configuration looks fine.
> > Are there any errors in error.log?
> > And what happens if you switch www.example.com and staging.example.com?
> >
> > --
> > Roman Arutyunyan
> > _______________________________________________
> > nginx mailing list
> > nginx@nginx.org
> > http://mailman.nginx.org/mailman/listinfo/nginx
>
> Kenny Meyer
> www.kennymeyer.net
>
> _______________________________________________
> nginx mailing list
> nginx@nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx

--
Roman Arutyunyan
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Kenny Meyer
Re: Using the mirror module
March 14, 2018 01:00PM
How do you define a resolver?

> On 13 Mar, 2018, at 19:36, Roman Arutyunyan <[email protected]> wrote:
>
> On Tue, Mar 13, 2018 at 06:58:25PM -0300, Kenny Meyer wrote:
>> Hi Roman,
>>
>>> Are there any errors in error.log?
>> No errors…
>>
>>> And what happens if you switch www.example.com and staging.example.com?
>> Then I get redirected to staging.example.com and I don’t see any requests being logged on example.com
>
> Do you have a resolver defined in the http{} block?
> Proxying to "http://staging.example.com$request_uri"; requires a resolver.
> Normally, you would have "no resolver defined to resolve ..."
> error logged if resolver is missing, but you may not see it if, for example,
> your log level is too high.
>
>>> On 13 Mar, 2018, at 18:34, Roman Arutyunyan <[email protected]> wrote:
>>>
>>> Hi Kenny,
>>>
>>> On Tue, Mar 13, 2018 at 05:37:52PM -0300, Kenny Meyer wrote:
>>>> Hi,
>>>>
>>>> I’m having trouble using the new mirror module. I want to mirror incoming requests from Nginx to other upstream servers. 1) a production server 2) a staging server
>>>>
>>>> This is my config:
>>>>
>>>> server {
>>>> listen 80 default_server;
>>>> listen [::]:80 default_server;
>>>>
>>>> location / {
>>>> mirror /mirror;
>>>> proxy_pass http://www.example.com;
>>>> }
>>>>
>>>> location /mirror {
>>>> internal;
>>>> proxy_pass http://staging.example.com$request_uri;
>>>> }
>>>> }
>>>>
>>>> So, I request http://myserver.com (where Nginx is hosted) and it successfully redirects me to www.example.com, however I don’t see any requests hitting staging.example.com.
>>>>
>>>> What could be the error?
>>>
>>> The configuration looks fine.
>>> Are there any errors in error.log?
>>> And what happens if you switch www.example.com and staging.example.com?
>>>
>>> --
>>> Roman Arutyunyan
>>> _______________________________________________
>>> nginx mailing list
>>> nginx@nginx.org
>>> http://mailman.nginx.org/mailman/listinfo/nginx
>>
>> Kenny Meyer
>> www.kennymeyer.net
>>
>> _______________________________________________
>> nginx mailing list
>> nginx@nginx.org
>> http://mailman.nginx.org/mailman/listinfo/nginx
>
> --
> Roman Arutyunyan
> _______________________________________________
> nginx mailing list
> nginx@nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx

Kenny Meyer
www.kennymeyer.net

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Peter Booth
Re: Using the mirror module
March 14, 2018 01:40PM
Suggestion:

Define two more locations - one that proxies www.example.com and another that proxies staging.example.com. If both locations work then your problem is probably mirroring. If one doesn’t work then the issue is your configuration and not mirroring. Either way you have reduced the size of your problem space.

Peter

Sent from my iPhone

> On Mar 13, 2018, at 5:58 PM, Kenny Meyer <[email protected]> wrote:
>
> Hi Roman,
>
>> Are there any errors in error.log?
> No errors…
>
>> And what happens if you switch www.example.com and staging.example.com?
> Then I get redirected to staging.example.com and I don’t see any requests being logged on example.com
>
>
>
>> On 13 Mar, 2018, at 18:34, Roman Arutyunyan <[email protected]> wrote:
>>
>> Hi Kenny,
>>
>>> On Tue, Mar 13, 2018 at 05:37:52PM -0300, Kenny Meyer wrote:
>>> Hi,
>>>
>>> I’m having trouble using the new mirror module. I want to mirror incoming requests from Nginx to other upstream servers. 1) a production server 2) a staging server
>>>
>>> This is my config:
>>>
>>> server {
>>> listen 80 default_server;
>>> listen [::]:80 default_server;
>>>
>>> location / {
>>> mirror /mirror;
>>> proxy_pass http://www.example.com;
>>> }
>>>
>>> location /mirror {
>>> internal;
>>> proxy_pass http://staging.example.com$request_uri;
>>> }
>>> }
>>>
>>> So, I request http://myserver.com (where Nginx is hosted) and it successfully redirects me to www.example.com, however I don’t see any requests hitting staging.example.com.
>>>
>>> What could be the error?
>>
>> The configuration looks fine.
>> Are there any errors in error.log?
>> And what happens if you switch www.example.com and staging.example.com?
>>
>> --
>> Roman Arutyunyan
>> _______________________________________________
>> nginx mailing list
>> nginx@nginx.org
>> http://mailman.nginx.org/mailman/listinfo/nginx
>
> Kenny Meyer
> www.kennymeyer.net
>
> _______________________________________________
> nginx mailing list
> nginx@nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Roman Arutyunyan
Re: Using the mirror module
March 14, 2018 01:40PM
On Wed, Mar 14, 2018 at 08:55:39AM -0300, Kenny Meyer wrote:
> How do you define a resolver?

Use the "resolver" directive:

http://nginx.org/en/docs/http/ngx_http_core_module.html#resolver

This only makes sense if your nginx resolves domain names in runtime.
In your configuration "staging.example.com" is resolved in runtime because
the entire URL contains a variable ($request_uri). However, if you put an ip
address instead, you will not need a resolver.

> > On 13 Mar, 2018, at 19:36, Roman Arutyunyan <[email protected]> wrote:
> >
> > On Tue, Mar 13, 2018 at 06:58:25PM -0300, Kenny Meyer wrote:
> >> Hi Roman,
> >>
> >>> Are there any errors in error.log?
> >> No errors…
> >>
> >>> And what happens if you switch www.example.com and staging.example.com?
> >> Then I get redirected to staging.example.com and I don’t see any requests being logged on example.com
> >
> > Do you have a resolver defined in the http{} block?
> > Proxying to "http://staging.example.com$request_uri"; requires a resolver.
> > Normally, you would have "no resolver defined to resolve ..."
> > error logged if resolver is missing, but you may not see it if, for example,
> > your log level is too high.
> >
> >>> On 13 Mar, 2018, at 18:34, Roman Arutyunyan <[email protected]> wrote:
> >>>
> >>> Hi Kenny,
> >>>
> >>> On Tue, Mar 13, 2018 at 05:37:52PM -0300, Kenny Meyer wrote:
> >>>> Hi,
> >>>>
> >>>> I’m having trouble using the new mirror module. I want to mirror incoming requests from Nginx to other upstream servers. 1) a production server 2) a staging server
> >>>>
> >>>> This is my config:
> >>>>
> >>>> server {
> >>>> listen 80 default_server;
> >>>> listen [::]:80 default_server;
> >>>>
> >>>> location / {
> >>>> mirror /mirror;
> >>>> proxy_pass http://www.example.com;
> >>>> }
> >>>>
> >>>> location /mirror {
> >>>> internal;
> >>>> proxy_pass http://staging.example.com$request_uri;
> >>>> }
> >>>> }
> >>>>
> >>>> So, I request http://myserver.com (where Nginx is hosted) and it successfully redirects me to www.example.com, however I don’t see any requests hitting staging.example.com.
> >>>>
> >>>> What could be the error?
> >>>
> >>> The configuration looks fine.
> >>> Are there any errors in error.log?
> >>> And what happens if you switch www.example.com and staging.example.com?
> >>>
> >>> --
> >>> Roman Arutyunyan
> >>> _______________________________________________
> >>> nginx mailing list
> >>> nginx@nginx.org
> >>> http://mailman.nginx.org/mailman/listinfo/nginx
> >>
> >> Kenny Meyer
> >> www.kennymeyer.net
> >>
> >> _______________________________________________
> >> nginx mailing list
> >> nginx@nginx.org
> >> http://mailman.nginx.org/mailman/listinfo/nginx
> >
> > --
> > Roman Arutyunyan
> > _______________________________________________
> > nginx mailing list
> > nginx@nginx.org
> > http://mailman.nginx.org/mailman/listinfo/nginx
>
> Kenny Meyer
> www.kennymeyer.net
>
> _______________________________________________
> nginx mailing list
> nginx@nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx

--
Roman Arutyunyan
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Sorry, only registered users may post in this forum.

Click here to login