should I creat two confs,one's piont to www,one without www
But If I delete one conf files , the DNS were not works.
…………………………………conf one………
server
{
listen 80;
server_name
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
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
server_name www.example.com example.com;
that will allow http requests for either the base domain or www (dot) base domain.
–
Travis
Let me try again.
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.