Apache服務器安裝

1.下載

登錄http://httpd.apache.org/download.cgi 這個地址,找到2.4.10,找到file for Windows

進入如下界面後,選擇第一項ApacheHaus,這是個第三方下載平臺,在它的網站下載獨立的Apache會是一個壓縮包

2.安裝

(1)找到D:\Apache24\conf\httpd.conf文件,用記事本打開,找到:Define SRVROOT 這一項,將其右方的值改爲

Define SRVROOT “D:\Apache24

(2)繼續找,找到:Listene 80

若你的80端口被佔用(可在cmd下用命令netstat -a查看),則將80端口改爲別的

保存httpd.conf文件。

(3)接下來需要配置安裝Apache的主服務,有了它,Apache纔可啓動:

打開CMD窗口,輸入:"D:\application_software\Apache\bin\httpd.exe" -k install -n apache

切記,包含引號。該命令的意思是,安裝apache服務,並將該服務名稱命名爲apache(你也可以改成別的),回車。

服務安裝完畢,完畢後,會自動測試,若有問題,窗口會提示錯誤,此時,請根據錯誤自行排查。

正常安裝完畢如下圖所示:

其中,Errors reported here must be corrected before the service can be started.意思是,若該句話後面有錯誤信息,則表示服務安裝失敗,需要先改正錯誤。若沒有,則成功。

(4)在安裝目錄中,找到D:Apache24\bin\ApacheMonitor.exe可執行文件,雙擊運行

(5)點擊左側start,啓動apache服務。

補充句,從該界面可看出,其可以手動控制服務的開啓與關閉,爲了節省資源,關閉Apache服務器的時候,請先點擊“Stop”關閉apache服務。

當然,該服務也可以在windows系統服務中關閉(建議設置成手動)

(6)打開瀏覽器,輸入訪問

http://localhost:端口號 若出現如下圖所示界面,則Apache服務器的基本配置完畢,此時apache服務器已經可以運行


3.遇到問題總結

(1)AH00072: make_sock: could not bind to address [::]:443 Aphache啓動報443端口占用

這裏443端口被佔用,我們可以通過netstat -ano查詢那個進程在使用這個端口

解決方法:

打開conf目錄下的httpd.conf,搜索ssl

找到:

# Secure (SSL/TLS) connections
# Note: The following must must be present to support
#       starting without SSL on platforms with no /dev/random equivalent
#       but a statically compiled-in mod_ssl.
#
<IfModule ssl_module>
#Include conf/extra/httpd-ssl.conf
Include conf/extra/httpd-ahssl.conf
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>

從上面的文字可以看出ssl的配置文件在conf/extra/httpd-ahssl.conf目錄下(注意:並不在conf/extra/httpd-ssl.conf目錄,這一句被註釋掉了)

將其中的443改成其他端口,如1443

第一處(Line 18)

Listen 443

改成

Listen 1443

第二處(Line 134,136)

<VirtualHost _default_:443>
  SSLEngine on
  ServerName localhost:443
  SSLCertificateFile "${SRVROOT}/conf/ssl/server.crt"
  SSLCertificateKeyFile "${SRVROOT}/conf/ssl/server.key"
  DocumentRoot "${SRVROOT}/htdocs"
# DocumentRoot access handled globally in httpd.conf
    CustomLog "${SRVROOT}/logs/ssl_request.log" \
          "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
    <Directory "${SRVROOT}/htdocs">
        Options Indexes Includes FollowSymLinks
        AllowOverride AuthConfig Limit FileInfo
    Require all granted
    </Directory>
</virtualhost>
改成

<VirtualHost _default_:1443>
  SSLEngine on
  ServerName localhost:1443
  SSLCertificateFile "${SRVROOT}/conf/ssl/server.crt"
  SSLCertificateKeyFile "${SRVROOT}/conf/ssl/server.key"
  DocumentRoot "${SRVROOT}/htdocs"
# DocumentRoot access handled globally in httpd.conf
    CustomLog "${SRVROOT}/logs/ssl_request.log" \
          "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
    <Directory "${SRVROOT}/htdocs">
        Options Indexes Includes FollowSymLinks
        AllowOverride AuthConfig Limit FileInfo
    Require all granted
    </Directory>
</virtualhost>

第三處(Line 150,152)

<VirtualHost *:443>
  SSLEngine on
  ServerName serverone.tld:443
  SSLCertificateFile "${SRVROOT}/conf/ssl/serverone.crt"
  SSLCertificateKeyFile "${SRVROOT}/conf/ssl/serverone.key"
  DocumentRoot "${SRVROOT}/htdocs"
    CustomLog "${SRVROOT}/logs/ssl_request.log" \
          "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
    <Directory "${SRVROOT}/htdocs">
        Options Indexes Includes FollowSymLinks
        AllowOverride AuthConfig Limit FileInfo
    Require all granted
    </Directory>
</virtualhost>
改成

<VirtualHost *:1443>
  SSLEngine on
  ServerName serverone.tld:1443
  SSLCertificateFile "${SRVROOT}/conf/ssl/serverone.crt"
  SSLCertificateKeyFile "${SRVROOT}/conf/ssl/serverone.key"
  DocumentRoot "${SRVROOT}/htdocs"
    CustomLog "${SRVROOT}/logs/ssl_request.log" \
          "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
    <Directory "${SRVROOT}/htdocs">
        Options Indexes Includes FollowSymLinks
        AllowOverride AuthConfig Limit FileInfo
    Require all granted
    </Directory>
</virtualhost>
第四處(Line 165,167)
<VirtualHost *:443>
  SSLEngine on
  ServerName servertwo.tld:443
  SSLCertificateFile "${SRVROOT}/conf/ssl/servertwo.crt"
  SSLCertificateKeyFile "${SRVROOT}/conf/ssl/servertwo.key"
  DocumentRoot "${SRVROOT}/htdocs"
    CustomLog "${SRVROOT}/logs/ssl_request.log" \
          "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
    <Directory "${SRVROOT}/htdocs">
        Options Indexes Includes FollowSymLinks
        AllowOverride AuthConfig Limit FileInfo
    Require all granted
    </Directory>
</virtualhost>
改成

<VirtualHost *:1443>
  SSLEngine on
  ServerName servertwo.tld:1443
  SSLCertificateFile "${SRVROOT}/conf/ssl/servertwo.crt"
  SSLCertificateKeyFile "${SRVROOT}/conf/ssl/servertwo.key"
  DocumentRoot "${SRVROOT}/htdocs"
    CustomLog "${SRVROOT}/logs/ssl_request.log" \
          "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
    <Directory "${SRVROOT}/htdocs">
        Options Indexes Includes FollowSymLinks
        AllowOverride AuthConfig Limit FileInfo
    Require all granted
    </Directory>
</virtualhost>




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章