1.什麼是apachehtml
Apache是世界使用排名第一的Web服務器軟件。它能夠運行在幾乎全部普遍使用的計算機平臺上,因爲其跨平臺和安全性被普遍使用,是最流行的Web服務器端軟件之一。它快速、可靠而且可經過簡單的API擴充,將Perl/Python等解釋器編譯到服務器中。同時Apache音譯爲阿帕奇,是北美印第安人的一個部落,叫阿帕奇族,在美國的西南部。httpd是Apache超文本傳輸協議(HTTP)服務器的主程序mysql
lamp=linux apache mysql phplinux
lnmp=linux nginx mysql phpnginx
雖然nginx(nginx提供共享)性能更好,可是不是開源web
相關命令sql
curl -I www.baidu.com(域名) 查看域名使用的信息apache
nmap 網絡掃描vim
yum install nmap -y 瀏覽器
nmap -A www.xupt.ed 在國外此命令違法
2.配置apache
①server端配置
hostnamectl set-hostname web1.westos.com
yum install httpd -y
cd /var/www/html/
systemctl start httpd
vim /etc/httpd/conf/httpd.conf
163 <IfModule dir_module>
164 DirectoryIndex index.html file
165 </IfModule>
在配置文件中,index.html和 file文件,哪一個在前,在瀏覽器中優先看哪一個,若都沒有,則瀏覽器顯示界面爲apache測試頁面
yum install httpd-manual.noarch -y httpd使用手冊
●更改默認發佈目錄:
將默認發佈目錄/var/www/html/改成/www/westos
[root@web1 ~]# cd /var/www/html/
[root@web1 html]# getenforce
Enforcing
[root@web1 html]# ls -Zd .
drwxr-xr-x. root root system_u:object_r:httpd_sys_content_t:s0 .
[root@web1 html]# mkdir /www/westos -p
[root@web1 html]# semanage fcontext -a -t httpd_sys_content_t '/www/westos(/.*)?'
[root@web1 html]# restorecon -RvvF /www/
restorecon reset /www context unconfined_u:object_r:default_t:s0->system_u:object_r:default_t:s0
restorecon reset /www/westos context unconfined_u:object_r:default_t:s0->system_u:object_r:httpd_sys_content_t:s0
[root@web1 html]# cd /www/westos/
[root@web1 westos]# vim index.html 編輯內容爲/www/westos's page
[root@web1 westos]# vim /etc/httpd/conf/httpd.conf 修改內容爲:
119 #DocumentRoot "/var/www/html"
120 DocumentRoot "/www/westos"
121 <Directory "/www/westos">
122 require all granted
123 </Directory>
[root@web1 westos]# systemctl restart httpd.service
在server瀏覽器中輸入http://172.25.254.149 獲得 /www/westos's page 表示更改爲功
●端口:
[root@web1 westos]# ss -antlp | grep httpd
LISTEN 0 128 :::80 :::*
[root@web1 westos]# vim /etc/httpd/conf/httpd.conf
41 #Listen 12.34.56.78:80
42 Listen 80 默認爲80端口
http://ip:80也可不加80通常默認
若改變爲Listen 8080,則在瀏覽器中輸入http://ip:8080
但8080端口容易被***利用***,慎用。
●訪問權限黑白名單
[root@web1 westos]# vim /etc/httpd/conf/httpd.conf
120 DocumentRoot "/www/westos"
121 <Directory "/www/westos">
122 require all granted
123 Order Deny,Allow **誰在前,先讀誰,通常Allow在前
124 Allow from 172.25.254.0/24 **容許172.25.254.x網段全部人訪問
125 Deny from ALL **拒絕全部人訪問
126 </Directory>
[root@web1 westos]# systemctl restart httpd.service
●設置用戶訪問權限
vim /etc/httpd/conf/httpd.conf
121 <Directory "/www/westos">
122 Require all granted
123 AllowOverride all
124 Authuserfile /etc/httpd/htpasswdfile 用戶信息所在文件
125 Authname "Please input username and password" 提示信息
126 Authtype basic 基本認證類型
127 Require user admin 只容許使用用戶admin在瀏覽器中訪問
128 </Directory>
systemctl restart httpd.service
若要因此用戶均可訪問則:
vim /etc/httpd/conf/httpd.conf
127 Require valid-user
systemctl restart httpd.service
訪問須要輸入用戶和密碼
●apaache的虛擬主機
vim /etc/httpd/conf/httpd.conf先修改成初始狀態
119 DocumentRoot "/var/www/html"
120 #DocumentRoot "/www/westos"
121 #
122 # Relax access to content within /var/www.
[root@web1 westos]# cd /etc/httpd/
[root@web1 httpd]# ls
conf conf.d conf.modules.d logs modules run
[root@web1 httpd]# htpasswd -cm htpasswdfile admin -c表示創建
New password:
Re-type new password:
Adding password for user admin
[root@web1 httpd]# htpasswd -m htpasswdfile westos 第二次新建不用加c,若加-c會覆蓋第一次創建的用戶信息
New password:
Re-type new password:
Adding password for user westos
[root@web1 httpd]# cat htpasswdfile
admin:$apr1$JICcD90s$CUjJyhcTEEHIz5x1qj55z1
westos:$apr1$6rk8RbXl$CIFniY0.TwqKr.oY.tvCg1
[root@web1 httpd]# vim /etc/httpd/conf/httpd.conf
[root@web1 httpd]# ll /etc/httpd/htpasswdfile
-rw-r--r--. 1 root root 89 Dec 8 01:17 /etc/httpd/htpasswdfile
vim /etc/httpd/conf/httpd.conf
[root@web1 httpd]# systemctl restart httpd.service
[root@web1 httpd]# cd /var/www/html/
[root@web1 html]# ls
index.html
[root@web1 html]# vim index.html 這裏是默認的
[root@web1 html]# mkdir /var/www/virtual/news.westos.com/html -p
[root@web1 html]# mkdir /var/www/virtual/music.westos.com/html -p
[root@web1 html]# cd /var/www/virtual/news.westos.com/html/
[root@web1 html]# vim index.html
[root@web1 html]# cd /var/www/virtual/music.westos.com/html/
[root@web1 html]# vim index.html
[root@web1 html]# cd /etc/httpd/conf.d/
[root@web1 conf.d]# ls
autoindex.conf manual.conf README userdir.conf welcome.conf
[root@web1 conf.d]# vim /etc/httpd/conf/httpd.conf
[root@web1 conf.d]# vim default.conf
[root@web1 conf.d]# vim music.conf
[root@web1 conf.d]# vim news.conf
[root@web1 conf.d]# ls
autoindex.conf manual.conf news.conf userdir.conf
default.conf music.conf README welcome.co
[root@web1 conf.d]# systemctl restart httpd
vim /etc/httpd/conf/httpd.conf 查看文件應該編輯的地方
353 IncludeOptional conf.d/*.conf
[root@westos named]# vim /etc/hosts 測試端:(在desktop上)
172.25.254.112 www.westos.com westos.com news.westos.com music.westos.com
firefox -->在瀏覽器中輸入不一樣的域名
若是顯示對應 ,則配置正確