http服务使用

一、http的基本设置

1)安装http服务

yum install httpd -y

2)查看http的默认设置

164|index.html /*是http的默认发布文件

119|/var/www/html /*是默认的

42|Listen 80 /*默认端口

3)如果不关闭防火墙需要修改selinux的标贴(ls  -Zd可以查看http的标贴)

mkdir /www/westos -p

semanage fcontext -a -t httpd_sys_content_t '/www/westos(/.*)?'

restorecon -RvvF /www/

4)更换默认发布目录,限制ip访问

vim /etc/httpd/conf/httpd.conf

120|DocumentRoot "/www/westos"

121|<Directory "/www/westos">

122| require all granted

</Directory>

121|<Directory "/www/westos">

require all granted

Order Allow,Deny

Allow from All

Deny from 172.25.254.150

126|</Directory>

二、设置用户登陆网页

1)建立用户及密码

cd /etc/httpd

htpasswd -cm htpasswdfile admin 

htpasswd -m htpasswdfile westos

121|<Directory "/www/westos">

AllowOverride All

Authuserfile /etc/httpd/htpasswdfile

Authname "Please input username and password"

Authtype basic

Require valid-user

</Directory>

2)建立多个访问页面

mkdir /var/www/virtual/news.linux.com/html -p

mkdir /var/www/virtual/music.linux.com/html -p

cd /var/www/virtual/news.linux.com/html

vim index.html

news.linux.com

cd /var/www/virtual/music.linux.com/html

vim index.html

music.linux.com

cd /etc/httpd/conf.d/

vim default.conf

<virtualhost_default_:80>

Documentroot /var/www/html

Customlog "logs/default.log" combined

</virtualhost>

<Directory "/var/www/html">

Required all granted

</Directory>


vim music.conf

<virtualhost *:80>

Servername music.linux.com

Documentroot /var/www/virtual/music.linux.com

Customlog "logs/music.log" combined

</virtualhost>

<Directory "/var/www/virtual/music.linux.com/html">

Required all granted

</Directory>


vim news.conf

<virtualhost *:80>

Servername news.linux.com

Documentroot /var/www/virtual/news.linux.com

Customlog "logs/news.log" combined

</virtualhost>

<Directory "/var/www/virtual/news.linux.com/html">

Required all granted

</Directory>

vim /etc/resolv.conf

172.25.254.150  music.linux.com news.linux.com www.linux.com

三、安全登陆https

yum install mod_ssl -y

yum install crypto-utils -y 

cd /etc/httpd/conf.d

5|Listen 443 https

genkey www.linux.com

wKiom1hKpt_zP_3ZAASB7n3duUQ556.png-wh_50

wKioL1hKpwSwVnV4AAHzCNspLpE260.png-wh_50

wKioL1hKpy-ilE4UAAWRYL6dhJ8253.png-wh_50

wKiom1hKp1ryFu_JAAT5W2Ai5OU455.png-wh_50

wKioL1hKp5GBG3KQAAkyhDMGbu0355.png-wh_50

wKioL1hKqAjgH8fYAAXIE1wY3Co709.png-wh_50