Welcome! Log In Create A New Profile

Advanced

Wildcard subdomains pointing each one to a folder with the same name as subdomain

Posted by dimitre 
Wildcard subdomains pointing each one to a folder with the same name as subdomain
May 13, 2015 04:03PM
Hello, nowadays I add a block for each subdomain like this:

server {
server_name instigado.hifolio.com;
root /home/hifolio/public_html/instigado;
include miolo.conf;
}

server {
server_name danca.hifolio.com;
root /home/hifolio/public_html/danca;
include miolo.conf;
}

server {
server_name smartgrids.hifolio.com;
root /home/hifolio/public_html/smartgrids;
include miolo.conf;
}


Is there some way of doing the same using wildcards, like using a regexp on $host variable or something like that?
Thank you very much.

Dimitre
Re: Wildcard subdomains pointing each one to a folder with the same name as subdomain
May 13, 2015 04:42PM
Maybe this helps: http://forum.nginx.org/read.php?2,258792

---
nginx for Windows http://nginx-win.ecsds.eu/
In fact it doesn't. thank you anyway
what I'm looking for is some help with a named regular expression, something like this but able to work with my particular example. Thank you

A named regular expression capture can be used later as a variable:

server {
server_name ~^(www\.)?(?<domain>.+)$;

location / {
root /sites/$domain;
}
}
Re: Wildcard subdomains pointing each one to a folder with the same name as subdomain
May 14, 2015 05:25PM
Ah then you need something like this:

map $host $dswcname {
default "www";
~smartgrids "smartgrids";
[...]
}

server {
listen 80;
server_name .site.eu;
[...]
root /home/hifolio/public_html/$dswcname;
[...]

---
nginx for Windows http://nginx-win.ecsds.eu/
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 240
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready