Question
Nginx redirect subdomain from www to non-www
Hello, I’m using this nginx conf:
root /var/www/html/laravel/public;
index index.php index.html index.htm index.nginx-debian.html;
server_name *.example.com;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.1-fpm.sock;
}
It is multi-tenancy project, I want redirect all subdomains with www to non-www. My question is, how? :) I have one config file for all subdomains.
In my root nginx conf I just used:
server {
server_name www.example.com;
return 301 $scheme://example.com$request_uri;
}
But in subdomains config I cant use it. My nginx conf skills are not very good, so pls help.
Thank you all
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
×
Not sure what you mean here:
There is no such thing as “subdomains” conf. Every site (virtual host) should have its own configuration file.