I want to configure nginx.conf for the below url
domain.com/user/suvojit => suvojit.domain.com
Till now my nginx configuration is as below
server {
listen 80; ## listen for ipv4
server_name domain.com;
root /var/www/html/project/frontend/web/;
index index.php;
access_log /var/www/html/project/vagrant/nginx/log/frontend-access.log;
error_log /var/www/html/project/vagrant/nginx/log/frontend-error.log;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
try_files $uri =404;
}
location ~ /\.(ht|svn|git) {
deny all;
}}
I am using Yii2 application. Is there anything need to specify there?
You need to had a server block to your nginx config
server {
listen 80; ## listen for ipv4
server_name ~^(?<user>[^.]+)\.example\.com$;
return 301 http://example.com/user/$user;
}
You also need to make sure that you make a wildcard subdomain entry in your DNS so that *.domain.com
resolves to your server
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.