安裝apache
準備工作:
1.準備好4種源碼包
apr-1.5.2.tar.gz
apr-util-1.5.2.tar.gz
pcre-8.43.tar.gz
httpd-2.4.41.tar.gz
2.通過wget 加上相關網址獲得
3.本文章安裝包網址
連結:https://pan.baidu.com/s/15gLvrCIL942ZNDF4PL5Bug
提取碼:r5er
一鍵準備好編譯器環境
yum install gcc gcc-c++ make expat-devel
安裝開始(按照順序安裝)
1、首先安裝apr依賴
(1) tar -zxf apr-1.5.2.tar.gz
(2) cd ./apr-1.5.2
(3) ./configure --prefix=/usr/local/webserver/apr //安裝路徑
(4) make
(5) make install
2、安裝apr-util
(1) tar -zxf apr-util-1.5.2.tar.gz
(2) cd ./apr-util-1.5.2
(3) ./configure --prefix=/usr/local/webserver/apr-util -with-apr=/usr/local/webserver/apr/bin/apr-1-config // 安裝路徑 并且 建立apr關聯
(4) make
(5) make install
3、安裝pcre
(1) tar -zxf pcre-8.43.tar.gz
(2) cd ./pcre-8.43
(3) ./configure --prefix=/usr/local/webserver/pcre // 安裝路徑
(4) make
(5) make install
4、安裝apache
(1) tar -zxf httpd-2.4.41.tar.gz
(2) cd ./httpd-2.4.41
(3) ./configure --prefix=/usr/local/webserver/apache --with-apr=/usr/local/webserver/apr --with-apr-util=/usr/local/webserver/apr-util --with-pcre=/usr/local/webserver/pcre // 安裝路徑并且與apr\apr-util\pcre建立聯系
(4) make
(5) make install
使用方式:此時可以通過Ip直接通路了
啟動方式:/usr/local/webserver/apache/bin/apachectl start | stop | restart (啟動|停止|重新開機)
注意:這裡可能會報一個警告

解決方式:
進入/usr/local/webserver/apache/conf打開httpd.conf檔案,把
這行去掉
額外設定:将httpd(Apache)設定為啟動服務
(1)複制到啟動目錄:cp /usr/local/webserver/apache/bin/apachectl /etc/rc.d/init.d/httpd
(2) 建立啟動關聯:ln -s /etc/rc.d/init.d/httpd /etc/rc.d/rc3.d/S61httpd (連結檔案的S61是啟動時的序号,當init.d目錄下有httpd腳本後,我們就可以通過service指令來啟動關閉apache了)
(3)添加運作資訊:cd /etc/rc.d/init.d
vim httpd 在第二行添加 # chkconfig: 35 61 61
# description: Apache
(4)chkconfig --add httpd(設定開機自動啟動)
(5)systemctl start httpd.service(啟動httpd,這時候Apache就又可以成功通路了)
修改配置(修改/usr/local/webserver/apache/conf/httpd.conf檔案)
例1:部門内搭建一台WEB伺服器,采用的IP位址和端口為192.168.0.3:80,首頁采用index.html檔案。管理者E- mail位址為[email protected],網頁的編碼類型采用GB2312,所有網站資源都存放在/var/www/html目錄下,并将 Apache的根目錄設定為/etc/httpd目錄。
編輯主配置檔案httpd.conf
ServerRoot “/etc/httpd” //設定Apache的主目錄
Timeout 120 //設定請求逾時
Listen 80 //設定監聽端口
ServerAdmin [email protected] //設定管理者郵箱
ServerName 192.168.0.3:80 //設定主機或IP
DocumentRoot “/var/www/html” //設定Apache文檔目錄
DirectoryIndex index.html //設定首頁檔案
AddDefaultCharset utf-8 //設定網站編碼
ErrorLog logs/smile-error_log //設定錯誤日志的存放位置
CustomLog logs/smile-access_log common //設定通路日志的存放位置
例2:假設Apache伺服器具有192.168.0.2和19.16.0.3兩個位址,然後配置Apache,把多個網站綁定在不同的IP位址上,通路伺服器上不同的IP位址,就可以看到不同的網站。
(基于域名)
mkdir /var/www/smile /var/www/long //建立兩個主目錄
編輯httpd.conf檔案:
<VirtualHost 192.168.0.3> //設定虛拟主機的IP
DocumentRoot /var/www/smile //設定虛拟主機的主目錄
DirectoryIndex index.html //設定首頁檔案
ServerName www.smile.com //設定虛拟主機完全域名
ServerAdmin [email protected] //設定管理者郵箱
ErrorLog logs/smile-error_log //設定錯誤日志的存放位置
CustomLog logs/smile-access_log common //設定通路日志的存放位置
<VirtualHost 192.168.0.3>
DocumentRoot /var/www/long
DirectoryIndex index.html
ServerName www.smile.com //設定虛拟主機完全域名
ServerAdmin [email protected]
ErrorLog logs/long-error_log
CustomLog logs/long-access_log common
(基于端口)
mkdir /var/www/port8080 /var/www/port8090 //建立兩個主目錄
編輯httpd.conf檔案:
Listen 8080
Listen 8090
<VirtualHost 192.168.0.3:8080> //設定相應的端口
DocumentRoot /var/www/port8080 //設定虛拟主機的主目錄
DirectoryIndex index.html //設定首頁檔案
ServerAdmin [email protected] //設定管理者郵箱
ErrorLog logs/port8080-error_log //設定錯誤日志的存放位置
CustomLog logs/port8080-access_log common //設定通路日志的存放位置
<VirtualHost 192.168.0.3:8090> //設定相應的端口
DocumentRoot /var/www/port8090
DirectoryIndex index.html
ServerAdmin [email protected]
ErrorLog logs/port8090-error_log
CustomLog logs/port8090-access_log common
<Directory “/var/www/html/test/”>
Options FollowSymLinks IncludesNOEXEC
AllowOverride All
Order Deny,Allow
Allow from all
安裝nginx
準備工作:
nginx-1.9.8.tar.gz安裝包
一鍵安裝相關環境:
yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel
安裝包的擷取:
1.直接上傳源檔案
2.或者wget http://nginx.org/download/nginx-1.9.8.tar.gz
解壓安裝包:
tar -xvf nginx-1.9.8.tar.gz
進入解壓檔案夾
cd ./nginx-1.9.8
然後執行
./configure --prefix=/usr/local/webserver/nginx // --prefix…這裡是編譯存放路徑
再依次執行
make
make install
配置相關:
進入/usr/local/webserver/nginx/conf/nginx.conf 配置檔案配置相關東西如:端口
然後執行一次關聯操作(作用在于指定啟動配置檔案的路徑)
/usr/local/webserver/nginx/sbin/nginx -c /usr/local/webserver/nginx/conf/nginx.conf
最後啟動:
/usr/local/webserver/nginx/sbin/nginx -s reload
檢視是否啟動
ps -ef | grep nginx
此時已經ok
可以通過浏覽器使用ip+端口通路得到nginx的預設頁面
如果嘗試外網通路失敗,檢查下防火牆相關内容!
僅供個人學習與記錄使用!