Report this

What is the reason for this report?

Nginx redirect subdomain from www to non-www

Posted on March 10, 2018

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

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Start building today

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.