Rewrite rule for all domains

Pardon me if I missed this in the docs…

My issue is that I want to rewrite every domain and not create a server
block for each.

I am trying to rewrite every domain thats pointing to Nginx

from www.server.com to server.com

currently I am doing uwsgi_pass unix://$host.sock

but if the host name has the www prefix then my socket is not found…

Currently I am using the default nginx.conf file with only one line
added uwsgi_pass

Thanks in advance for any help.

On 16 April 2013 15:47, David | StyleFlare [email protected] wrote:

Pardon me if I missed this in the docs…

My issue is that I want to rewrite every domain and not create a server
block for each.

I am trying to rewrite every domain thats pointing to Nginx

from www.server.com to server.com

Have a single separate server block do it for you:

server {
listen 80;
server_name ~^(www.)(?.+)$;
rewrite $scheme://$domain$uri$is_args$args;
}

(written but not tested; YMMV!)

Jonathan

Thanks, I will test it.

Appreciate it.

Adding to Jonathan suggestion with a twist:

  1. Use a map directive at the http level:

    map $host $rewrite_domain {
    default 0;
    ~www.(?.*)$ $domain;
    }

  2. Create a default server while leaving all vhosts using only the base
    domain.

    server {
    listen 80 default_server;

     if ($rewrite_domain) {
         return 301 $scheme://$rewrite_domain$request_uri;
     }
    

    }

----appa