centos6.5安装apache2.x并更改默认80port

因为现在nginx它已成为反向代理软件的主流。因此,linuxserver在系统。我们几乎总是安装nginx东方的,这使在同一时间使用apache带来了麻烦。因为apache它用于通过缺省80port。


和其他许多倍。我们显然不希望更改nginx的port。改动apache的80port。

1.首先查找apache的httpd服务的配置文件httpd.conf,用rpm,yum等不同方式安装的apache的文件夹有所不同,我这里是安装centos6.5时就已经选择安装了apache2.2.15。配置文件位于/etc/httpd/conf/httpd.conf。首先编辑这个文件
找到Listen 80这一行,改动为

Listen 8000
继续改动httpd.conf文件,找到
#ServerName www.example.com:80
在以下添加一行
ServerName localhost:8000
改动保存httpd.conf后。运行
# service httpd restart
糟糕。会出现非常多错误提示,主要是
Permission denied: make_sock: could not bind to address [::]:8000

2.须要尝试运行semanage添加8000port,运行
# semanage port -l|grep http
假设没有semanage命令。能够先安装semanage及selinux
# yum provides /usr/sbin/semanage
或者
# yum whatprovides /usr/sbin/semanage
查看一下,然后运行安装命令:
yum -y install policycoreutils-python

安装完后又一次运行
#semanage port -l|grep http
http_cache_port_t              tcp      3128, 8080, 8118, 8123, 10001-10010
http_cache_port_t              udp      3130
http_port_t                    tcp      80, 81, 443, 488, 8008, 8009, 8443, 9000
pegasus_http_port_t            tcp      5988
pegasus_https_port_t           tcp      5989
可是在某些机器上运行上面的命令。可能会出现下面错误提示:
# semanage port -l|grep http
/usr/sbin/semanage: SELinux policy is not managed or store cannot be accessed.
显示策略有问题,一般来说重新启动系统能够解决问题。

假设可以正确运行。可以看到我的server列表中不包括8000port。于是运行
# semanage port -a -t http_port_t -p tcp 8000
/usr/sbin/semanage: port tcp/8000 已经存在
却显示8000port已存在,这时候细致观察,发现http_port_t中包括9000port,于是我将apache配置文件里的port的两处配置改为了9000port

3.再次重新启动httpd服务,提示apache启动成功了,假设须要,能够在nginx配置文件nginx.conf中代理apache的9000port。这样就能够不用输入port号直接訪问你的apache服务了。
然而这里有个疑问。在我的机器上。9000port已经存在于selinux中。apache最后使用了9000port,会不会有神马冲突或隐患。哪位对selinux有深刻理解的专家是否能给解释一下。

4.最后,假设iptables中间9000port没开,您可以添加防火墙规则。



版权声明:本文博客原创文章。博客,未经同意,不得转载。

原文地址:https://www.cnblogs.com/gcczhongduan/p/4684194.html