听多个端口httpd fedora

时间:2015-10-15 07:02:18

标签: http fedora

如何设置httpd来监听多个端口,就像在apache ports.conf

中一样

我想添加一些仅在某些端口上可用的虚拟主机

2 个答案:

答案 0 :(得分:0)

编辑默认配置文件:

vim /etc/httpd/conf/httpd.conf <-- requires root privileges

并添加:

Listen 80
Listen 81
....
Listen 8x

现在,对于vhosts:

<VirtualHost *:80>
     ServerName server1 <-- this needs to be in your /etc/hosts file
     DocumentRoot /var/www/project1
</VirtualHost>
<VirtualHost *:81>
     ServerName server2 <-- this needs to be in your /etc/hosts file
     DocumentRoot /var/www/project2
</VirtualHost>

在此之后,请务必重新启动httpd:

/etc/init.d/httpd restart <-- requires root privileges

最后,访问两个网站,例如:http://server1:80http://server2:81

更新: Fedora还需要更新SElinux策略,允许httpd访问非默认端口(例如90):

semanage port -a -t http_port_t -p tcp 90 <-- requires root privileges

答案 1 :(得分:0)

在Fedora 29上

省掉你的头痛

确保已在firewall-cmd命令上添加了端口

sudo firewall-cmd --permanent --add-port=<port>/tcp

在您的httpd.conf中添加Listen <port>时,请确保SELINUX不是Enforcing

SEMANAGE上没有Fedora 29,与旧版本不同。

#check if selinux is enforcing
> getenforce
Enforcing

#If enforcing turn it off
> sudo setenforce 0

#check again if we successfully turned off enforcing
> getenforce
Permissive

#Now we start httpd
> sudo systemctl start httpd

# return selinux to enforcing
> sudo setenforce 1