0

Can someone explain why they say this in the nginx documentation? Why is it "cumbersome and ineffective"?

A redirect to a main site

People who during their shared hosting life used to configure everything using only Apache’s .htaccess files, usually translate the following rules:

RewriteCond  %{HTTP_HOST}  nginx.org
RewriteRule  (.*)          http://www.nginx.org$1
to something like this:

server {
    listen       80;
    server_name  www.nginx.org  nginx.org;
    if ($http_host = nginx.org) {
        rewrite  (.*)  http://www.nginx.org$1;
    }
    ...
}

This is a wrong, cumbersome, and ineffective way. The right way is to define a separate server for nginx.org:

server {
    listen       80;
    server_name  nginx.org;
    return       301 http://www.nginx.org$request_uri;
}

server {
    listen       80;
    server_name  www.nginx.org;
    ...
}

1 Answer 1

1

Because every time you hit the site in the first option it will recheck the host header if to redirect you or not. and on the second it will not happen, sending some cpu cycles to garbage.

:)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .