httpd:是一個提供網站服務的程序html
監聽端口:80node
環境準備:apache
Linux CentOS7.3系統vim
使用一臺服務端,一臺客戶端便可;服務器
1、安裝httpdide
1:安裝測試
[root@localhost ~]# systemctl stop firewalld 優化
[root@localhost ~]# setensorce 0 網站
[root@localhost ~]# rpm -e httpd –nodeps #卸載系統自帶的httpdui
[root@localhost ~]# mkdir /media/cdrom #建立掛載點文件夾
[root@localhost ~]# mount /dev/cdrom /media/cdrom #掛載光盤
[root@localhost ~]# yum -y install gcc* apr-devel apr-util-devel pcre-devel #安裝開發包
[root@localhost ~]# tar zxvf httpd-2.4.25.tar.gz #解壓縮包
[root@localhost ~]# cd httpd-2.4.25
[root@localhost httpd-2.4.25]# ./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-charset-lite --enable-cgi
註釋:
--prefix:制定程序的安裝目錄
--enable-so:啓用動態加載模塊DSO的支持,使httpd具有進一步擴展功能的能力
--enable-rewrite:啓用網頁地址重寫功能,用於網站優化
--enable-charset-lite:啓動字符集支持,以便支持使用各類字符集編碼的網頁
--enable-cgi:啓用cgi腳本程序支持,擴展網站的應用訪問能力
[root@localhost httpd-2.4.25]# make && make install
[root@localhost httpd-2.4.25]# ls /usr/local/httpd
[root@localhost httpd-2.4.25]# /usr/local/httpd/bin/apachectl start
[root@localhost httpd-2.4.25]# netstat -anpt |grep httpd
[root@localhost httpd-2.4.25]# /usr/local/httpd/bin/apachectl stop
[root@localhost httpd-2.4.25]# netstat -anpt |grep httpd
2:優化執行路徑
[root@localhost httpd-2.4.25]# ln -s /usr/local/httpd/bin/* /usr/local/bin/
[root@localhost httpd-2.4.25]# ls -l /usr/local/bin/httpd /usr/local/bin/apachectl
#查看軟鏈接
[root@localhost httpd-2.4.25]# httpd -v
[root@localhost httpd-2.4.25]# apachectl start
[root@localhost httpd-2.4.25]# netstat -anpt |grep httpd
[root@localhost httpd-2.4.25]# apachectl stop
[root@localhost httpd-2.4.25]# netstat -anpt |grep httpd
3:添加httpd系統服務
使用chkconfig添加爲系統服務
[root@localhost httpd-2.4.25]# cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd #複製配置文件
[root@localhost httpd-2.4.25]# vi /etc/init.d/httpd //編輯配置文件
添加:
#!/bin/sh
#chkconfig:35 85 21
#description:httpd server
[root@localhost httpd-2.4.25]# chkconfig --add httpd #加入系統服務,開機啓動
[root@localhost httpd-2.4.25]# chkconfig --list httpd
[root@localhost httpd-2.4.25]# service httpd start #啓動httpd
2、httpd服務器的基本配置
1:肯定網站的名稱、ip地址和域名
2:配置並啓動httpd
[root@localhost ~]# vim /usr/local/httpd/conf/httpd.conf
修改(前面的數字是行號):
ServerName www.bdqn.com ##200行
[root@localhost ~]# apachectl -t #檢測配置文件語法
2:啓動httpd服務
[root@localhost ~]# systemctl start httpd #啓動httpd
[root@localhost ~]# netstat -anpt | grep httpd
3:部署網頁
[root@localhost ~]# vim /usr/local/httpd/htdocs/index.html #編輯主頁
<html><body><h1>It works!</h1></body></html>
[root@localhost ~]# service httpd restart #重啓httpd服務
4:測試
打開網站
http://192.168.10.101
5:查看站點訪問狀況
[root@localhost ~]# tail /usr/local/httpd/logs/access_log
[root@localhost ~]# tail /usr/local/httpd/logs/error_log
3、httpd.conf配置文件解釋
1:全局配置項
[root@localhost ~]# vim /usr/local/httpd/conf/httpd.conf ServerRoot "/usr/local/httpd" Listen 80 #監聽端口(默認80) User daemon #用戶 (默認daemon) Group daemon #用戶組(默認daemon) ServerAdmin you@example.com #郵箱地址 ServerName www.bdqn.com #網站域名 DocumentRoot "/usr/local/httpd/htdocs" #網頁存儲位置 DirectoryIndex index.html #默認主頁 ErrorLog "logs/error_log" #錯誤日誌文件存儲位置 LogLevel warn #日誌級別 CustomLog "logs/access_log" common #正常訪問日誌
Include conf/extra/proxy-html.conf #虛擬主機路徑
|
2:區域配置項
[root@localhost ~]# vim /usr/local/httpd/conf/httpd.conf <Directory /> #根目錄 AllowOverride none Require all denied </Directory>
<Directory "/usr/local/httpd/htdocs"> #限制路徑 Options Indexes FollowSymLinks AllowOverride None Require all granted #容許全部主機訪問還能夠拒絕全部人訪問 </Directory> |