SteveLTN / https-portal

A fully automated HTTPS server powered by Nginx, Let's Encrypt and Docker.
MIT License
4.46k stars 295 forks source link

Question: URL rewrite #282

Closed jrcichra closed 3 years ago

jrcichra commented 3 years ago

Hi, I was wondering if it's already possible, or if would be easy to implement, a URL rewrite feature with some similarity to HTTPRewrite in Istio: https://istio.io/latest/docs/reference/config/networking/virtual-service/#HTTPRewrite.

I'm looking at a simple use case, something like this:

   webcam1.example.com    -> http://securityfeed/cam1,
   webcam2.example.com    -> http://securityfeed/cam2

...where based on the hostname, the proxy will rewrite the / request to go to /cam1

My particular use case doesn't need complex rules, just truncating part of the URL.

From your docs, today it looks like CUSTOM_NGINX_<UPPERCASE_AND_UNDERSCORED_DOMAIN_NAME>_CONFIG_BLOCK plus modifying this server level block would do the trick for me:

https://www.journaldev.com/26864/nginx-rewrite-url-rules

          location = / 
          { 
            rewrite ^/$ /cam break; 
          }

but maybe this feature built-in would be useful to other people, if you can simply rewrite a URL. Perhaps there are similar use cases with cameras.example.com/cam1 -> camera1.

This sounds like a fun feature to implement and I'd be willing to make a PR. What are your thoughts? Thanks.

SteveLTN commented 3 years ago

Hi,

Can't you use redirection for this?

For such simple case as yours, redirect seems adequate. AFAIK rewrite is usually used for very complex scenarios, which is hard to configure in a ENV block anyway.