Score:0

Find out domain in URI in Nginx Conf

do flag

The question of url is domain.com/proxy/seconddomain.tld/images/file.jpg and we want to find what seconddomain.tld is so far we are trying nginx map module

map $request_uri $topdir {
        ~(?<captured_topdir>^/proxy/[a-zA-Z0-9\.-_]+)[/] $captured_topdir;
}

but this is returning empty, can say its okay to get /proxy/seconddomain.tld but need it without the folders.

us flag
How do you use `$topdir` variable?
Muhammad Hussain avatar
do flag
Use it in subs_filter to update image, link and asset urls.
us flag
You should fix the application instead to generate correct URLs. This is unnecessary and badly maintainable hack to do the asset URLs.
Score:0
za flag

Try this:

if ($host ~* ^(.+)\.([a-z0-9-]+)$) {
   set $domainpart $1;
   set $tld $2;
}
Score:0
in flag

@drookie

This is not working please, it is causing a 502 error

if ($host ~* ^(.+)\.([a-z0-9-]+)$) {
   set $domainpart $1;
   set $tld $2;
}

                add_header X-domain "$domainpart";
                add_header X-tld "$tld";
                subs_filter_types *;
                subs_filter 'action="/'  action="/proxy/$domainpart.$tld/;
                subs_filter 'href="/'  href="/proxy/$domainpart.$tld/;

It works if I take the if part out and set the domainpart and tld to fixed variables.

Thanks

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.