阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

CentOS 6.5安装Apache2.x并修改默认80端口

148次阅读
没有评论

共计 2171 个字符,预计需要花费 6 分钟才能阅读完成。

因目前 Nginx 已经成了主流反向代理软件,所以在 Linux 服务器系统上,我们几乎都会安装 Nginx 这个东东,这就给同时使用 Apache 带来了麻烦,因为 Apache 缺省使用的也是 80 端口。

而更多时候,我们显然不想修改 nginx 的端口,于是只有修改 apache 的 80 端口。

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 增加 8000 端口,执行

# 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.

显示策略有问题,一般来说重启系统可以解决这个问题。
 
如果能够正确执行,可以看到我的服务器列表中不包含 8000 端口,于是执行

# semanage port -a -t http_port_t -p tcp 8000
/usr/sbin/semanage: 端口 tcp/8000 已经存在

却显示 8000 端口已存在,这时候仔细观察,发现 http_port_t 中包含 9000 端口,于是我将 apache 配置文件中的端口的两处配置改为了 9000 端口

3. 再次重启 httpd 服务,提示 apache 启动成功了,如果需要,可以在 nginx 配置文件 nginx.conf 中代理 apache 的 9000 端口,这样就可以不用输入端口号直接访问你的 apache 服务了。

然而这里有个疑问,在我的机器上,9000 端口已经存在于 selinux 中,apache 最后使用了 9000 端口,会不会有神马冲突或隐患,哪位对 selinux 有深刻理解的专家能否给解释一下。

4. 最后,如果 iptables 中的 9000 端口未打开,就增加这个防火墙规则即可。

————————————– 分割线 ————————————–

Ubuntu 13.04 安装 LAMP\Vsftpd\Webmin\phpMyAdmin 服务及设置 http://www.linuxidc.com/Linux/2013-06/86250.htm

CentOS 5.9 下编译安装 LAMP(Apache 2.2.44+MySQL 5.6.10+PHP 5.4.12) http://www.linuxidc.com/Linux/2013-03/80333p3.htm

RedHat 5.4 下 Web 服务器架构之源码构建 LAMP 环境及应用 PHPWind http://www.linuxidc.com/Linux/2012-10/72484p2.htm

LAMP 源码环境搭建 WEB 服务器 Linux+Apache+MySQL+PHP http://www.linuxidc.com/Linux/2013-05/84882.htm

LAMP+Xcache 环境搭建 http://www.linuxidc.com/Linux/2014-05/101087.htm

————————————– 分割线 ————————————–

更多 CentOS 相关信息见CentOS 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=14

正文完
星哥说事-微信公众号
post-qrcode
 
星锅
版权声明:本站原创文章,由 星锅 2022-01-20发表,共计2171字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中