Answer the question
In order to leave comments, you need to log in
nginx. How to setup redirect from subdomain to routing file?
Hello!
The bottom line is this: there is a bunch of Nginx + CentOS + PHP. There is a domain www.site.com.
There is an index.php router file at the root of the site. A user can register on the site, a "separate" subdomain is allocated for him.
Problem: I can't configure Nginx to redirect client.site.com to the main site's file router. Moreover, in the router file I would like to get some parameter that this is such and such a subdomain. Client folders exist, but they cannot contain their handler. Only custom images, etc. A prerequisite for setting up is that these subdomains must have their own SEO indicators (search engine indexing, traffic, and so on).
Maybe someone has already implemented this?
PS Explained not very clear. Here is an example of work:
1) The user visits www.site.com. site.com/index.php gives him the main site
2) The user registers and receives the client.site.com subdomain. The site.com/client/ folder is created for the user
3) The user goes to client.site.com... site.com/index.php - gives him the display and template of the client.site.com site
4) client.site.com is indexed search engines, etc.
Thank you in advance!
Answer the question
In order to leave comments, you need to log in
I will give only the key parts of the config:
server {
server_name site.com www.site.com;
root /path/to_you/site_dir;
location ~ /user/$ {
deny all;
access_log off;
log_not_found off;
}
location ~ \.php$ {
...
fastcgi_param USER_SUBDOMAIN "_MAIN_";
...
}
}
server {
server_name "~^(?<user_subdomain>[a-z0-9_-]{2,20})\.site\.com$";
root /path/to_you/site_dir;
location ~ /assets/$ {
alias /path/to_you/site_dir/user/$user_subdomain/
}
location ~ \.php$ {
...
fastcgi_param USER_SUBDOMAIN $user_subdomain;
...
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question