为了学习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、下载软件
wget http://archive.apache.org/dist/apr/apr-1.4.5.tar.gz
wget http://archive.apache.org/dist/apr/apr-util-1.3.12.tar.gz
wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.10/pcre-8.10.zip
wget http://archive.apache.org/dist/apr/apr-util-1.3.12.tar.gz
wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.10/pcre-8.10.zip
到官网下载包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