apache服务

yum search http

yum install httpd.x86_64 -y

systemctl start httpd

systemctl  enable httpd

firewall-cmd --list-all

firewall-cmd --permanent --add-service=http         //将http加入firewall-cmd中,防火墙就不会组织他的运行

firewall-cmd --permanent --add-service=https

firewall-cmd --reload

firewall-cmd --list-all

cd /var/www/html

vim index.html

--------------------

hello world jsfdsjf

---------------------

测试:在浏览器中输入IP,就可以看见index.html的内容

 

 

改变apache的端口。默认发布文件

默认端口为80

vim /etc/httpd/conf/httpd.conf   

 40 #

 41 #Listen 12.34.56.78:80

 42 Listen 8080               //修改为8080端口

 43

systemctl restart httpd

firewall-cmd --permanent --add-port=8080/tcp

firewall-cmd --reload

测试:在浏览器中输入172.25.254.246:8080

 

 

119 #DocumentRoot "/var/www/html"

120 #

121 DocumentRoot "/www/html"

122 # Relax access to content within /var/www.

123 #

124     //默认目录

125     AllowOverride None

126     # Allow open access:

127     Require all granted

 

162 #

163

164     DirectoryIndex index.html linux   //默认发布文件为index.html,先查看index.html再查看linux文件,修改文件顺序可以改变默认先读取的文件

165

 

 

cd /var/www/html

vim linux

-------------

hello world

123

---------------------

cd /etc/httpd/conf.d/

 

vim default.conf             //虚拟主机配置文件

---------------------

          //虚拟主机的块,默认端口80

          Documentroot /var/www/html  //提供内容的目录

          customlog "logs/default.log" combined

 

          require all granted

----------------------

 

mkdir /var/www/news

mkdir /var/www/music

cd /var/www/news/

 

vim  westos

-------------------

you are very good

-----------------

cd /etc/httpd/conf.d

 

vim news.conf         //虚拟主机news的配置文件

---------------------

         Servername news.westos.com //服务器的名称

           Documentroot /var/www/news  

          customlog "logs/news.log" combined

 

          require all granted

---------------------------------

cd /var/www/music/

vim linux

---------------------------------

asdhofhal;sdnfajsodofj

---------------------------------

cd /etc/httpd/conf.d/

 

vim music.conf        //虚拟主机music的配置文件

---------------------------------

         Servername music.westos.com

           Documentroot /var/www/music

          customlog "logs/music.log" combined

 

          require all granted

--------------------------------------------------

selinux标签

semanage fcontext -l

semanage fcontext -a -t httpd_sys_content_t "/directory(/.*)?"

restorecon -vvFR /directory

 

systemctl start httpd

systemctl enable httpd

配置真机的/etc/hosts

172.25.254.146 www.westos.com news.westos.com music.westos.com

在浏览器中输入:www.westos.com

             news.westos.com

             music.wetos.com

 

基于用户的身份认证

 

htpasswd -cm apacheusr admin    //创建admin密码文件

htpasswd -m apacheusr tom         //创建tom密码文件

cat apacheusr                   //查看密码文件

 

vim news.conf                              

----------------------------------

         Servername news.westos.com

           Documentroot /var/www/news

          customlog "logs/news.log" combined

 

          require all granted

          Authuserfile /etc/http/conf/apacheusr   //用户密码文件目录

          Authname "Please input your name and password" //登陆提示

           Authtype basic

           Require valid-user               //所有可用用户

---------------------------------------

测试:在浏览器中输入:news.westos.com/admin

 

 

 

自定义签名证书

yum install mod_ssl -y

cd /etc/httpd/conf.d

yum install crypto-utils -y

genkey  apache.example.com

vim ssl.conf

Servername login.westos.com

Documentroot /var/www/login

Customlog logs/login.log combined

SSLEngine on

SSLCertificateFile /etc/pki/tls/certs/apache.example.com.crt

SSLCertificateFile /etc/pki/tls/private/apache.example.com.key

/var/www/login>

     Require all granted

     Servername login.westos.com

     RewriteEngine on

     RewriteRule ^(/.*)$ https://%{HTTP_HOST}$1 [redirect=301]  

---------------------------------------------------------------------------------

systemctl restart httpd

mkdir -p  /var/www/login

vim /var/www/login/index.com

systemctl restart httpd