apache单ip配置多端口多站点

1.修改 /etc/httpd/conf/httpd.conf

添加一个Listen,如:

Listen 80
Listen 8001
Listen 8002

2.添加一个VirtualHost

#vim /etc/httpd/conf.d/vhost.conf
NameVirtualHost *:8001
<VirtualHost *:8001>
DocumentRoot /var/www/html/public_html
ServerName localhost
ServerAdmin test@gmail.com
#ErrorLog "| /usr/sbin/rotatelogs /var/www/html/log/public_html_error_%Y_%m_%d.log 86400 480"
#CustomLog "| /usr/sbin/rotatelogs /var/www/html/log/public_html_access_%Y_%m_%d.log 86400 480" common
ErrorLog "/var/www/html/log/error.log"
CustomLog "/var/www/html/log/access.log" common
</VirtualHost> NameVirtualHost *:8002
<VirtualHost *:8002>
DocumentRoot /var/www/html/phpmyadmin
ServerName localhost
ServerAdmin test@gmail.com
#ErrorLog "| /usr/sbin/rotatelogs /var/www/html/log/public_html_error_%Y_%m_%d.log 86400 480"
#CustomLog "| /usr/sbin/rotatelogs /var/www/html/log/public_html_access_%Y_%m_%d.log 86400 480" common
ErrorLog "/var/www/html/log/error.log"
CustomLog "/var/www/html/log/access.log" common
</VirtualHost>

3.为新端口添加防火墙规则

iptables -I INPUT -p tcp --dport 8001 -j ACCEPT
/etc/rc.d/init.d/iptables save

4.禁用selinux(如果不禁用,会无法重新启动apache)

方法1.关闭selinux

vim /etc/selinux/config

首先将SELINUX=enforcing添加注释

#SELINUX=enforcing

然后在文件末尾添加如下代码

SELINUX=disabled

方法2.修改selinux规则
首先查看现在支持http的端口有哪些

semanage port -l | grep http

然后为http服务新的端口号

semanage port -a -t http_port_t -p tcp 8001

查看添加的结果

semanage port -l | grep http

5.重启httpd服务

service httpd restart
上一篇:大神教你如何解决Linux系统80端口被占用


下一篇:配置 Apache+php多端口多站点(转载)