A while ago, I created a simple internal short URL service (with Django).
If an entry exists, for example, /abc (or whatever), it redirects to the stored, longer URL with a HTTP-Status of 301. So far, so good...
However, now I have the requirement to set up this service for the main website.
However, there is already a CMS running with nginx try_files and proxy_pass configured.
Nginx:
location / {
try_files /maintenance.html $uri @cms;
}
location @cms {
rewrite ^/(.*)/$ /$1 permanent;
rewrite ^(.*)$ /VirtualHostBase/$scheme/$host:$server_port/cms/VirtualHostRoot$1 break;
proxy_pass http://example_cms;
include /etc/nginx/cfg/proxy.conf;
include /etc/nginx/cfg/security.conf;
gzip_static on; # to serve pre-gzipped version
}
Can these be combined? So, the desired flow is as follows:
- if
/abcfound and returned in the short URL service, redirect with a HTTP Status from URL-Service; - otherwise, use the CMS and display a URL from the CMS using
try_files+rewrite+proxy_pass. - If none of these apply, show a 404, which can also be served by the CMS.