监听多个端口的httpd fedora
Listen to multiple port httpd fedora
如何像在 apache 中一样设置 httpd 来监听多个端口 ports.conf
我想添加一些仅在某些端口上可用的虚拟主机
编辑默认配置文件:
vim /etc/httpd/conf/httpd.conf <-- requires root privileges
并添加:
Listen 80
Listen 81
....
Listen 8x
现在,对于虚拟主机:
<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:80
、http://server2:81
更新:
Fedora 还需要更新 SElinux 策略,允许 httpd 访问非默认端口(例如 90):
semanage port -a -t http_port_t -p tcp 90 <-- requires root privileges
在 Fedora 29 上
让你不再头疼
确保您已经在 firewall-cmd
命令中添加了端口
sudo firewall-cmd --permanent --add-port=<port>/tcp
将 Listen <port>
添加到 httpd.conf 时,请确保 SELINUX
不是 Enforcing
Fedora 29
上没有 SEMANAGE
不像旧的
#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
如何像在 apache 中一样设置 httpd 来监听多个端口 ports.conf
我想添加一些仅在某些端口上可用的虚拟主机
编辑默认配置文件:
vim /etc/httpd/conf/httpd.conf <-- requires root privileges
并添加:
Listen 80
Listen 81
....
Listen 8x
现在,对于虚拟主机:
<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:80
、http://server2:81
更新: Fedora 还需要更新 SElinux 策略,允许 httpd 访问非默认端口(例如 90):
semanage port -a -t http_port_t -p tcp 90 <-- requires root privileges
在 Fedora 29 上
让你不再头疼
确保您已经在 firewall-cmd
命令中添加了端口
sudo firewall-cmd --permanent --add-port=<port>/tcp
将 Listen <port>
添加到 httpd.conf 时,请确保 SELINUX
不是 Enforcing
Fedora 29
上没有 SEMANAGE
不像旧的
#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