web服務器的搭建


 為了學習web服務器的搭建,主要步驟如下:

1、安裝軟件:

  sudo apt update   //更新軟件源

  sudo apt upgrade  //更新軟件

  sudo apt install apache2  //安裝apache2軟件包

2、配置web服務器,主要涉及兩個文件的配置/etc/apache2/apache2.conf

  配置選項:

 1 # It is split into several files forming the configuration hierarchy outlined
 2 # below, all located in the /etc/apache2/ directory:
 3 #
 4 #       /etc/apache2/
 5 #       |-- apache2.conf
 6 #       |       `--  ports.conf
 7 #       |-- mods-enabled
 8 #       |       |-- *.load
 9 #       |       `-- *.conf
10 #       |-- conf-enabled
11 #       |       `-- *.conf
12 #       `-- sites-enabled
13 #               `-- *.conf
14 #
15 #
16 
17 DefaultRuntimeDir ${APACHE_RUN_DIR}
18 
19 PidFile ${APACHE_PID_FILE}
20 Timeout 300
21 KeepAlive On
22 MaxKeepAliveRequests 100
23 KeepAliveTimeout 5
24 
25 User ${APACHE_RUN_USER}
26 Group ${APACHE_RUN_GROUP}
27 HostnameLookups Off
28 ErrorLog ${APACHE_LOG_DIR}/error.log
29 LogLevel warn
30 IncludeOptional mods-enabled/*.load
31 IncludeOptional mods-enabled/*.conf
32 Include ports.conf
33 <Directory />
34         Options FollowSymLinks
35         AllowOverride None
36         Require all denied
37 </Directory>
38 
39 <Directory /usr/share>
40         AllowOverride None
41         Require all granted
42 </Directory>
43 
44 <Directory /var/www/>
45         Options Indexes FollowSymLinks
46         AllowOverride None
47         Require all granted
48 </Directory>
49 
50 AccessFileName .htaccess
51 <FilesMatch "^\.ht">
52         Require all denied
53 </FilesMatch>
54 
55 LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
56 LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
57 LogFormat "%h %l %u %t \"%r\" %>s %O" common
58 LogFormat "%{Referer}i -> %U" referer
59 LogFormat "%{User-agent}i" agent
60 IncludeOptional conf-enabled/*.conf
61 IncludeOptional sites-enabled/*.conf
62 
63 # vim: syntax=apache ts=4 sw=4 sts=4 sr noet

3、測試web服務器

  打開瀏覽器,在地址欄輸入IP:127.0.0。1,結果如下:

 4、應用web服務器,將需要展示的主頁頁面內容放置到/var/www/html,並且名字為index.html,注意權限問題,重新打開localhost頁面,應該顯示自己選定的主頁內容。

5、需要源碼編譯,需要准備好軟件包,使用: 

  a、下載軟件 

  到官網下載包 httpd-2.4.23.tar.gz
  b、解壓軟件:
  tar -xzvf apr-1.4.5.tar.gz
  tar -xzvf apr-util-1.3.12.tar.gz
  unzip pcre-8.10.zip
  tar -xzvf hattpd-2.4.23.tar.gz
  c、編譯安裝軟件,順序apr,apr-util, pcre, httpd
  過程如下:    進入源碼目錄 cd apr
           配置安裝信息: ./configure --prefix=/usr/local/apr
        編譯軟件:sudo make
        安裝軟件:sudo make install
  其他軟件也一樣。
 

./configure --prefix=/usr/local/web/apache --enable-shared=max --enable-module=rewirte --enable-module=so

./configure --prefix=/usr/local/apr-util -with-apr=/usr/local/apr/bin/apr-1-config

sudo ./configure --prefix=/usr/local/apache --enable-shared=max --enable-module=rewirte --enable-mod ule=so --with-apr=/usr/local/apr/ --with-apr-util=/user/local/apr-util --with-pcre=/usr/local/pcre


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM