CENTOS 创建好第一个WordPress网站后,/var/www/html
接着创建第一个网站 www.web2.com
首先,在/html下创建目录web2
mkdir web2
第二,将主网站的代码复制到web2目录下
[root@localhost html]# cd /var/www/html
[root@localhost html]# mkdir web2
[root@localhost html]# cp -rf /var/www/html/* /var/www/html/web2/
第三 ,为第二个网站创建数据库和用户
mysql> CREATE DATABASE db2;
mysql> CREATE USER db2User@localhost;
mysql> SET PASSWORD FOR db2User@localhost= PASSWORD("密码");
mysql> GRANT ALL PRIVILEGES ON db2.* TO gudianbook2User@localhost IDENTIFIED BY '密码';
mysql> FLUSH PRIVILEGES;
第四步 修改数据库名 用户名
vi /var/www/html/web2/wp-config.php
第五步:修改/etc/httpd/conf/httpd.conf添加网站
<pre name="code" class="cpp"> NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /var/www/html
ServerName www.shanghelaodoufu.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /var/www/html/xinlinglier
ServerName www.xinlinglier.com
</VirtualHost>
但是这样会有个问题 ,就是输入shanghelaodoufu.com后,会可能跳到www.xinlinglier.com中
所以要避免这种情况,必须把WWW 和没有WWW的都写上 才可以。
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /var/www/html
ServerName www.shanghelaodoufu.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /var/www/html/xinlinglier
ServerName www.xinlinglier.com
</VirtualHost>
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /var/www/html
ServerName shanghelaodoufu.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /var/www/html/xinlinglier
ServerName xinlinglier.com
</VirtualHost>
又如我自己的另外两个网站,之前,因为只写了没有WWW的,当输入WWW.gudianxiaoshuo.com 时候,往往会跳到needdown.com页面,这显示不是我希望的,于是,将有WWW前缀的和没有WWW前缀的都设置好后,就可以正确的跳转了
NameVirtualHost *:80
<VirtualHost *:80>
ServerName needdown.com
DocumentRoot /var/www/html/needdown
</VirtualHost>
NameVirtualHost *:80
<VirtualHost *:80>
ServerName www.needdown.com
DocumentRoot /var/www/html/needdown
</VirtualHost>
<VirtualHost *:80>
ServerName gudianxiaoshuo.com
DocumentRoot /var/www/html
</VirtualHost>
<VirtualHost *:80>
ServerName www.gudianxiaoshuo.com
DocumentRoot /var/www/html
</VirtualHost>
RewriteEngine on
RewriteMap lowercase int:tolower
RewriteMap vhost txt:/etc/httpd/vhost.map
RewriteCond ${lowercase:%{SERVER_NAME}} ^(.+)$
RewriteCond ${vhost:%1} ^(/.*)$
RewriteRule ^/(.*)$ %1/$1