should I creat two confs,one's piont to www,one without www

I try to domain my name url register without typing www. in front.

But If I delete one conf files , the DNS were not works.

…………………………………conf one………

server

{

listen 80;

server_name www.xxx.com;

index index.html index.htm index.php default.html default.htm default.php;

root /home/lovelytruth;

include wordpress.conf;

location ~ .*.(php|php5)?$

{

fastcgi_pass unix:/tmp/php-cgi.sock;

fastcgi_index index.php;

include fcgi.conf;

}

location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$

{

expires 30d;

}

location ~ .*.(js|css)?$

{

expires 12h;

}

access_log off;

}

……………………two………….

server

{

listen 80;

server_name www.xxx.com;

index index.html index.htm index.php default.html default.htm default.php;

root /home/lovelytruth;

include wordpress.conf;

location ~ .*.(php|php5)?$

{

fastcgi_pass unix:/tmp/php-cgi.sock;

fastcgi_index index.php;

include fcgi.conf;

}

location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$

{

expires 30d;

}

location ~ .*.(js|css)?$

{

expires 12h;

}

access_log off;

}

4 Replies

I think what your looking for is a single configuration with:

server_name www.example.com example.com;

that will allow http requests for either the base domain or www (dot) base domain.

Travis

Thanks !!1

Let me try again.

That will make www.example.com and example.com load the same content, and some search engines might think that you've got two different sites with identical content. Not good for SEO, according to received wisdom.

The best solution is to have the www version be the "real" website, and if anyone doesn't type www, automatically redirect them to the www version. (Or you can do it the other way around if you don't like www.)

This would require one full configuration, followed by a small stub for the redirect.

server {
    listen 80;
    server_name www.example.com;
    ... lots of other stuff ...
}

server {
    server_name example.com;
    rewrite ^ http://www.example.com$request_uri? permanent;
}

Not that this may be unnecessary if your CMS automatically handles canonical URLs. WordPress does this.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct