Answer the question
In order to leave comments, you need to log in
How to set up dynamic subdomains on nginx with a single front controller?
Hello.
There is a local project.
Installed nginx web server.
How to configure nginx so that when accessing a subdomain, for example sub.domain.com , the site works, but the request is sent to the front controller - domain.com .
All I need is to transfer the subdomain to the router / application and, based on the subdomain, get the necessary data from the database.
server {
listen 80;
listen [::]:80;
root /home/alex/mf/dcms/public;
index index.php index.htm index.nginx-debian.html;
server_name dcms.lo www.dcms.lo;
location / {
include /etc/nginx/mime.types;
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
}
location /assets {
alias /home/alex/mf/dcms/assets/;
try_files $uri $uri =404;
}
location ~ /\.ht {
deny all;
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question