天天看點

httpd服務

{**apache**}

lamp=linux apache mysql php

lnmp=linux nginx mysql php

nginx提供共享

curl -I www.baidu.com(域名) **檢視域名使用的資訊

nmap 網絡掃描

yum install nmap -y

nmap -A www.xupt.edu

在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>

**預設釋出目錄下/var/www/html/的index.html file檔案,哪個在前,在浏覽器中優先看哪個,若都沒有,則浏覽器顯示界面為apache測試頁面(在server浏覽器中輸入http://172.25.254.149,回車後可看到相應頁面)

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   表示更改成功

httpd服務

檢視端口:

[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

如:  http://172.25.254.149:8080

通路權限黑白名單

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      

設定使用者通路權限

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

若要是以使用者都可通路則:

127        Require valid-user

通路需要輸入使用者和密碼

httpd服務

{**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會覆寫第一次建立的使用者資訊

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

[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 這裡是news

[root@web1 html]# cd /var/www/virtual/music.westos.com/html/

[root@web1 html]# vim index.html 這裡是music

[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

httpd服務

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.149 www.westos.com westos.com news.westos.com music.westos.com

firefox -->在浏覽器中輸入不同的域名

music.westos.com  顯示music.westos.com(vim index.conf編輯的内容)界面

其他一樣

上一篇: httpd篇
下一篇: AWStats日志

繼續閱讀