2019年11月20日 17:32 阅读量:1419
主配置无需修改 /etc/httpd/conf/httpd.conf
,新建一个virtualhost配置文件/etc/httpd/conf.d/vhosts.conf
,内容如下
<VirtualHost *:80>
ServerAdmin root@localhost
DocumentRoot "/var/www/html"
ServerName localhost #默认站点
ServerAlias localhost
ErrorLog "logs/default-error_log"
#Customlog "logs/default-access_log" common
<Directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride all
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName xx.xx.xx.xx #屏蔽直接用服务器ip访问站点
<Directory />
Order Allow,Deny
Deny from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin root@localhost
DocumentRoot "/var/www/web"
ServerName www.aaa.com
ServerAlias www.aaa.com www.bbb.com ## 多个域名访问同一个站点
# RedirectMatch permanent ^/(.*) http://wx.aaa.com/$1 #301重定向
ErrorLog "logs/www.aaa.com-error_log"
#Customlog "logs/www.aaa.com-access_log" common
<Directory "/var/www/web">
Options Indexes FollowSymLinks
AllowOverride all
Require all granted
</Directory>
</VirtualHost>
配置修改好可以用 httpd -t
检测apche配置是否正确,重启apche systemctl restart httpd