centos vps下 apache绑定多个域名,多个目录
centos下 apache绑定多个域名,多个目录
apache怎么绑定多个域名
默认httpd.conf文件在/etc/httpd/config/httpd.conf 打开httpd.conf 1,ServerName 127.0.0.1 修改成ServerName 72.167.11.30
2,#NameVirtualHost * 修改成"NameVirtualHost 72.167.11.30"
3,在文件最后面有虚拟主机格式,
#<VirtualHost *>
# ServerAdmin [email]admin@45it.com[/email]
# DocumentRoot /www/httpd/html/45it.com
# ServerName 45it.com
# ErrorLog logs/45it.com-error_log
# CustomLog logs/45it.com-access_log common
#</VirtualHost>
简单的添加:
<VirtualHost 72.167.11.30>
DocumentRoot usr/local/www/
ServerName 72.167.11.30
</VirtualHost>
<VirtualHost 72.167.11.30>
DocumentRoot usr/local/www/jsjtt.com/
ServerName jsjtt.com
ServerAlias *.jsjtt.com
ErrorLog /sym/logs/jsjtt.com-error_log
CustomLog /sym/logs/jsjtt.com-access_log common
</VirtualHost>
<VirtualHost 72.167.11.30>
DocumentRoot usr/local/www/yaqu.com/
ServerName yaqudian.taobao.com
ServerAlias *.yaqudian.taobao.com
ErrorLog /sym/logs/yaqudian.com-error_log
CustomLog /sym/logs/yaqudian.com-access_log common
</VirtualHost>
日志文件的话也可以按照自己的路径添加。
Apache如何添加二级域名
httpd.conf 中需要打开mod_rewrite功能(关于URL重定向的具体说明,可以参照.htaccess使用方法总结),具体操作就是,在httpd.conf 的最后,添加以下内容:
RewriteEngine on
RewriteMap lowercase int:tolower
RewriteMap vhost txt:/usr/local/etc/apache/vhost.map
RewriteCond ${lowercase:%{SERVER_NAME}} ^(.+)$
RewriteCond ${vhost:%1} ^(/.*)$
RewriteRule ^/(.*)$ %1/$1
其中的 /usr/local/etc/apache 是你的 apache 服务器配置文件所在路径,根据实际情况更改(例如在/etc/httpd/下面)。然后,在这个所在路径的目录下创建一个文件: vhost.map,内容为:
www.jsjtt.com /usr/local/www/jsjtt.com
www.jsjtt.com /usr/local/www/jsjtt.com
blog.jsjtt.com /usr/local/www/jsjtt.com/blog
最后,在网站根目录 /usr/local/www/下,创建对应目录就可以了。如果需要增加,修改或者删除域名,子域名,仅仅需要更改vhost.map文件,而不用重启apache进程。