Allow internal redirect to URI x, but deny external request for x?

Francis Daly francis at daoine.org
Fri Aug 30 20:33:19 UTC 2019


On Fri, Aug 30, 2019 at 12:33:17PM -0500, J. Lewis Muir wrote:

Hi there,

> I'm wishing to be able to do an internal redirect
> in nginx to URL x, but deny an external request to the same URL x so
> that I don't serve the same content at more than one URL.  Is there a
> way to do that?
> 
> For example, given the external request URI
> 
>   /my-app/index.html
> 
> I want to do an internal redirect to
> 
>   /my-app/current/index.html
> 
> but deny an external request for that same URI
> 
>   /my-app/current/index.html

It sounds like you want "internal": http://nginx.org/r/internal

> In my nginx config, I've changed $document_root to $realpath_root in the
> appropriate FastCGI parameters, and have the following locations:
> 
>   location /my-app/ {
>     rewrite ^/my-app/(?!current/)(.*)$ /my-app/current/$1 last;
>     index index.php;
>   }
> 
>   location /my-app/current/ {
>     return 404;
>   }
> 
>   location /my-app/releases/ {
>     return 404;
>   }
> 
>   location ~ ^/my-app/.*?[^/]\.php(?:/|$) {
>     include php-fpm-realpath.conf;
>   }

Note that you might want things like "location ^~ /my-app/current/",
if you want that location to handle (and reject) an external request
for /my-app/current/app.php.

	f
-- 
Francis Daly        francis at daoine.org


More information about the nginx mailing list