
Custom subdomains
With the advent of new projects on the network, sometimes it seems that the task of effectively organizing user subdomains (bob.someblog.com) seems difficult for someone. In fact, this issue is resolved in one minute.
It is understood that nginx is used as the front-end of the http server , and the true location of the user directory is / users / bob /.
To proxy the domain bob.someblog.com and all its subdirectories to the address someblog.com/users/bob/, you can use the following nginx setting:
[a-z0-9 _ \ -] - this character class is determined by the rules of user registration, namely the set of valid characters that the name can consist of.
The only negative is the inconvenience of using an address like www.someblog.com , one of the solutions is to redirect visitors to someblog.com:
UPD: We are talking about these kinds of projects, where without an easy front-end north, such as nginx, nowhere.
UPD2: The discussion showed that I was still outdated and inherited the solution from the old version of nginx, where there were a lot of things. You can read a slightly more modern solution at http://server-tuning.info/nginx/auto-subdomains.html . Thanks ugnich
It is understood that nginx is used as the front-end of the http server , and the true location of the user directory is / users / bob /.
To proxy the domain bob.someblog.com and all its subdirectories to the address someblog.com/users/bob/, you can use the following nginx setting:
# someblog.com server { listen 11.22.33.44:80; server_name someblog.com * .someblog.com; charset utf8; location / { # Proxy user domains to / users / $ username if ($ host ~ * "^ (([a-z0-9 _ \ -] +) \. someblog \ .com) $") { set $ uid $ 2; rewrite ^ (. *) $ / users / $ uid $ 1 break; } ...
[a-z0-9 _ \ -] - this character class is determined by the rules of user registration, namely the set of valid characters that the name can consist of.
The only negative is the inconvenience of using an address like www.someblog.com , one of the solutions is to redirect visitors to someblog.com:
if ($ host ~ * "^ www \ .someblog \ .com $") { rewrite ^ (. *) $ http: //someblog.com$1 last; }
UPD: We are talking about these kinds of projects, where without an easy front-end north, such as nginx, nowhere.
UPD2: The discussion showed that I was still outdated and inherited the solution from the old version of nginx, where there were a lot of things. You can read a slightly more modern solution at http://server-tuning.info/nginx/auto-subdomains.html . Thanks ugnich