{"id":515,"date":"2015-01-20T15:08:54","date_gmt":"2015-01-20T15:08:54","guid":{"rendered":"http:\/\/www.tech-g.com\/?p=515"},"modified":"2015-01-20T15:08:54","modified_gmt":"2015-01-20T15:08:54","slug":"nginx-rewriting-sub-domain-into-a-directory-internally","status":"publish","type":"post","link":"https:\/\/www.voodoo.business\/blog\/2015\/01\/20\/nginx-rewriting-sub-domain-into-a-directory-internally\/","title":{"rendered":"nginx rewriting sub domain into a directory internally"},"content":{"rendered":"<p>To make a long story short, the most efficient way of doing this is simply to change the document root according to the sub domain<\/p>\n<p>So within your server stanza, you can simply do the following<\/p>\n<pre>\r\nserver_name ~^(?<sub>.+)\\.tech-g\\.com$;\r\n    root \/var\/www_nginx\/$sub;\r\n<\/pre>\n<p>This way, when you add a directory such as myothersite.com inside your nginx web directory, visitors comming to myothersite.com.tech-g.com will end up being served content from the directory \/var\/www_nginx\/myothersite.com<\/p>\n<p>No rewriting URLs needed, and no evil if statements either<\/p>\n","protected":false},"excerpt":{"rendered":"<p>To make a long story short, the most efficient way of doing this is simply to change the document root according to the sub domain So within your server stanza, you can simply do the following server_name ~^(?.+)\\.tech-g\\.com$; root \/var\/www_nginx\/$sub; This way, when you add a directory such as myothersite.com inside your nginx web directory, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-515","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/posts\/515","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/comments?post=515"}],"version-history":[{"count":1,"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/posts\/515\/revisions"}],"predecessor-version":[{"id":516,"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/posts\/515\/revisions\/516"}],"wp:attachment":[{"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/media?parent=515"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/categories?post=515"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.voodoo.business\/blog\/wp-json\/wp\/v2\/tags?post=515"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}