[prev in list] [next in list] [prev in thread] [next in thread] 

List:       nginx
Subject:    Re: rewrite rule: MediaWiki to static site
From:       Jeff Dyke <jeff.dyke () gmail ! com>
Date:       2018-08-20 22:35:18
Message-ID: CAHmnZdZ2taL7jenouZcAs9ji_-NgFcPnWfJuPa8xHByzeLK_vg () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Seems like you have a solution, but i've done this recently in the reverse
and found this configuration to be incredibly helpful, with little reason
to ever update.  I check the primary (static in my case) site first and if
it 404's it is sent to a different proxy_pass.  As you can guess i use the
Play Framework.

  location @corporate {
    proxy_pass http://corporate-server$uri;
    proxy_intercept_errors on;
    recursive_error_pages on;
    error_page 404 = @play;
  }

location @play {
    proxy_pass http://play-server$uri;
  }

then in the main location block i simply have:

location / {
    include /etc/nginx/shared_foo;  #this is simply shared headers, nothing
to do with the logic
    try_files $uri @corporate;
  }

As @corporate will send to @play only if required.

I mainly put it out here b/c if someone is searching, this is a way to go
about it, without creating a map.  We will add more to static and more to
Play overtime, as we already have, and this keeps on chugging.

Best,
Jeff

On Mon, Aug 20, 2018 at 4:10 PM petecooper <nginx-forum@forum.nginx.org>
wrote:

> Francis Daly Wrote:
>
> > In this case, it looks to me that you can probably "return" rather
> > than
> > "rewrite", since everything should probably be a http redirect.
> > non-Mediawiki URL
>
> > [...] Except I would have the config be not a lot more than
> >
> >   location = /wiki/index.php { return 301
> > https://example.net/$my_static_wiki; }
>
> >   map $arg_title $my_static_wiki {
> >     default ""; # or whatever
> >     en/Main_Page MainPage;
> >     Glossary Glossary;
> >     Category:Troubleshooting Troubleshooting;
> >   }
> >
> > Make that map (http://nginx.org/r/map) be as big as you like. And you
> > can
> > "include" an external file if you find that easier.
>
> > Good luck with it,
>
> Hello Francis -- thank you very much, that worked perfectly.
>
> The length of the `map` list meant I had to increase `map_hash_bucket_size`
> to `128`, but everything works as you described.
>
> with very best regards, and my heartfelt thanks;
>
> Pete
>
> Posted at Nginx Forum:
> https://forum.nginx.org/read.php?2,280913,280922#msg-280922
>
> _______________________________________________
> nginx mailing list
> nginx@nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx
>

[Attachment #5 (text/html)]

<div dir="ltr">Seems like you have a solution, but i&#39;ve done this recently in the \
reverse and found this configuration to be incredibly helpful, with little reason to \
ever update.   I check the primary (static in my case) site first and if it 404&#39;s \
it is sent to a different proxy_pass.   As you can guess i use the Play \
Framework.<div><br></div><div>   location @corporate {<br></div><div>      proxy_pass \
<a href="http://corporate-server">http://corporate-server</a>$uri;</div><div>      \
proxy_intercept_errors on;</div><div>      recursive_error_pages on;</div><div>      \
error_page 404 = @play;</div><div>   }    </div><div><br></div><div><div>location \
@play {</div><div>      proxy_pass <a \
href="http://play-server">http://play-server</a>$uri;</div><div>   \
}</div></div><div><br></div><div>then in the main location block i simply \
have:</div><div><br></div><div><div>location / {</div><div>      include \
/etc/nginx/shared_foo;   #this is simply shared headers, nothing to do with the \
logic</div><div>      try_files $uri @corporate;</div><div>   \
}</div></div><div><br></div><div>As  @corporate will send to  @play only if required. \
</div><div><br></div><div>I mainly put it out here b/c if someone is searching, this \
is a way to go about it, without creating a map.   We will add more to static and \
more to Play overtime, as we already have, and this keeps on chugging.  \
</div><div><br></div><div>Best,<br>Jeff</div></div><br><div class="gmail_quote"><div \
dir="ltr">On Mon, Aug 20, 2018 at 4:10 PM petecooper &lt;<a \
href="mailto:nginx-forum@forum.nginx.org">nginx-forum@forum.nginx.org</a>&gt; \
wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 \
.8ex;border-left:1px #ccc solid;padding-left:1ex">Francis Daly Wrote:<br> <br>
&gt; In this case, it looks to me that you can probably &quot;return&quot; rather<br>
&gt; than<br>
&gt; &quot;rewrite&quot;, since everything should probably be a http redirect.<br>
&gt; non-Mediawiki URL<br>
<br>
&gt; [...] Except I would have the config be not a lot more than<br>
&gt; <br>
&gt;     location = /wiki/index.php { return 301<br>
&gt; <a href="https://example.net/$my_static_wiki" rel="noreferrer" \
target="_blank">https://example.net/$my_static_wiki</a>; }<br> <br>
&gt;     map $arg_title $my_static_wiki {<br>
&gt;        default &quot;&quot;; # or whatever<br>
&gt;        en/Main_Page MainPage;<br>
&gt;        Glossary Glossary;<br>
&gt;        Category:Troubleshooting Troubleshooting;<br>
&gt;     }<br>
&gt; <br>
&gt; Make that map (<a href="http://nginx.org/r/map" rel="noreferrer" \
target="_blank">http://nginx.org/r/map</a>) be as big as you like. And you<br> &gt; \
can<br> &gt; &quot;include&quot; an external file if you find that easier.<br>
<br>
&gt; Good luck with it,<br>
<br>
Hello Francis -- thank you very much, that worked perfectly.<br>
<br>
The length of the `map` list meant I had to increase `map_hash_bucket_size`<br>
to `128`, but everything works as you described.<br>
<br>
with very best regards, and my heartfelt thanks;<br>
<br>
Pete<br>
<br>
Posted at Nginx Forum: <a \
href="https://forum.nginx.org/read.php?2,280913,280922#msg-280922" rel="noreferrer" \
target="_blank">https://forum.nginx.org/read.php?2,280913,280922#msg-280922</a><br> \
<br> _______________________________________________<br>
nginx mailing list<br>
<a href="mailto:nginx@nginx.org" target="_blank">nginx@nginx.org</a><br>
<a href="http://mailman.nginx.org/mailman/listinfo/nginx" rel="noreferrer" \
target="_blank">http://mailman.nginx.org/mailman/listinfo/nginx</a><br> \
</blockquote></div>



_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic