nginx的多域名配备 防止没有www时瞎跳

nginx的多域名配置 防止没有www时瞎跳

nginx装好后,默认的nginx.conf只有一个的server配置。

一般是像酱紫的:

 

server
 {
  listen       80;
  server_name www.91loli.com;
  index index.html index.htm index.php;
  root  /home/www;
  location ~ .*\.(php|php5)?$
   {
    fastcgi_pass  unix:/tmp/php-cgi.sock;
    fastcgi_index index.php;
    include fcgi.conf;
   }
  location /status {
   stub_status on;
   access_log   off;
  }
  location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
   {
    expires      30d;
   }
  location ~ .*\.(js|css)?$
   {
    expires      12h;
   }
  log_format  access  '$remote_addr - $remote_user [$time_local] "$request" '
             '$status $body_bytes_sent "$http_referer" '
             '"$http_user_agent" $http_x_forwarded_for';
  access_log  /home/logs/access.log  access;
 }
 

当然可以把N个虚拟主机都放进nginx.conf里面,但是这样不便管理。

所以配置文件下面华丽的插入:

 

include /usr/local/nginx/vhost/*.conf;

这样就可以包含N个虚拟主机的配置了。

虚拟主机的配置就不写了,上面有现成的可以抄。

 

下面是解决多个域名(多个虚拟主机)时,访问没有www的域名会跳转到默认域名的问题。

例如我的~访问yjkong.com,会跳转到www.91loli.com。关键是搜索引擎也会傻乎乎的收录进去。

废话不多说,只需要多写一个server_name

 

server_name www.yjkong.com;
server_name yjkong.com;

 

 

我滴网站:御姐控 就要萝莉

1 楼 yzhkpli 2011-07-16  
哥一般是写成一行。nginx的多域名配备 防止没有www时瞎跳