Francis Daly
September 14, 2013 05:00AM
On Sat, Sep 14, 2013 at 01:42:49AM -0400, etrader wrote:

Hi there,

> server {
> server_name domain.com *.domain.com
> root /var/www/$server_name;
> }

http://nginx.org/r/server_name

Look for "Named captures".

> is it possible to set locations for subdomains based on subfolders of the
> $server_name ?
>
> location matching sub1.domain.com {
> serving from /var/www/$server_name/sub1
> }

"location" doesn't match the hostname used. You could use a "map" to
enumerate the hostnames you consider valid, with a default value for
anything else; and use that in "root".

> Currently, I am using a server for each subdomain, but when the number of
> subdomains increases, maintaining numerous servers becomes messy.

If *every* valid hostname is handled equivalently, you could get away
with it being all in one server block.

But you may want to look into "include", or using an external-to-nginx
template system to turn your starting system into an nginx.conf with
multiple server blocks, if different hostnames are handled differently.

f
--
Francis Daly francis@daoine.org

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

How to serve subdomain from subfolder of the domain root?

etrader September 14, 2013 01:42AM

Re: How to serve subdomain from subfolder of the domain root?

Francis Daly September 14, 2013 05:00AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 236
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