1. 程式人生 > >CentOS7.0 Apache2.4.x 多埠監聽配置

CentOS7.0 Apache2.4.x 多埠監聽配置

1 檢視Apache 版本

#httpd -v

如果返回的結果不是2.4.x 版本,下面配置方式不適用。

2 檢視httpd 所在路徑

#whereis httpd

3 根據第2步的結果中找到conf檔案所在目錄

4 使用vim開啟httpd.conf

#vim /etc/httpd/conf

5 修改配置

在Listen 80的下一行新增

Listen 8080 (可以新增其他埠)

在檔案結尾新增如下xml片段

<VirtualHost localhost:8080>

   ServerAdmin [email protected]

   ServerName localhost:8080

   DocumentRoot “/home/stanley/mybooks/public”

   DirectoryIndex index.php

   <Directory “/home/stanley/mybooks/public”>

      Options Indexes Includes FollowSymlinks

      AllowOverride All

      Require all granted

   </Directory>

   ErrorLog /var/log/httpd/err_8080.log

   LogLevel warn

   CustomLog /var/log/httpd/err_8080_access.log combined

</VirtualHost>

6 測試httpd.conf檔案語法

#httpd -t

或者

#apachectl -t

7 測試

#curl localhost:8080

8 可能出現的錯誤

頁面可能顯示如下訊息:”You don’t have permission to access s/ on this server”,此時檢視xml 片段中指定的err_8080.log檔案,如果出現如下錯誤提示:”because search permissions are missing on a component of the path”,意思是xml配置的檔案路徑”/home/stanley/mybooks/public”中,某一級別的路徑不能正常訪問,解決的方式是遞迴改變路徑的訪問許可權:

#chmod 755 /home/stanley -R