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 <Directory "/www/html"> //默認目錄
125 AllowOverride None
126 # Allow open access:
127 Require all granted
162 #
163 <IfModule dir_module>
164 DirectoryIndex index.html linux //默認發佈文件爲index.html,先查看index.html再查看linux文件,修改文件順序可以改變默認先讀取的文件
165 </IfModule>
cd /var/www/html
vim linux
-------------
hello world
123
---------------------
cd /etc/httpd/conf.d/
vim default.conf //虛擬主機配置文件
---------------------
<Virtualhost *:80> //虛擬主機的塊,默認端口80
Documentroot /var/www/html //提供內容的目錄
customlog "logs/default.log" combined
</Virtualhost>
<Directory /var/www/html>
require all granted
</Directory>
----------------------
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的配置文件
---------------------
<Virtualhost *:80>
Servername news.westos.com //服務器的名稱
Documentroot /var/www/news
customlog "logs/news.log" combined
</Virtualhost>
<Directory /var/www/news>
require all granted
</Directory>
---------------------------------
cd /var/www/music/
vim linux
---------------------------------
asdhofhal;sdnfajsodofj
---------------------------------
cd /etc/httpd/conf.d/
vim music.conf //虛擬主機music的配置文件
---------------------------------
<Virtualhost *:80>
Servername music.westos.com
Documentroot /var/www/music
customlog "logs/music.log" combined
</Virtualhost>
<Directory /var/www/music>
require all granted
</Directory>
--------------------------------------------------
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
----------------------------------
<Virtualhost *:80>
Servername news.westos.com
Documentroot /var/www/news
customlog "logs/news.log" combined
</Virtualhost>
<Directory /var/www/news>
require all granted
</Directory>
<Directory /var/www/news/admin>
Authuserfile /etc/http/conf/apacheusr //用戶密碼文件目錄
Authname "Please input your name and password" //登陸提示
Authtype basic
Require valid-user //所有可用用戶
</Directory>
---------------------------------------
測試:在瀏覽器中輸入: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
<Virtualhost *:443>
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
</Virtualhost>
<Directory “/var/www/login”>
Require all granted
</Directory>
<Virtualhost *:80>
Servername login.westos.com
RewriteEngine on
RewriteRule ^(/.*)$ https://%{HTTP_HOST}$1 [redirect=301]
</Virtualhost>
---------------------------------------------------------------------------------
systemctl restart httpd
mkdir -p /var/www/login
vim /var/www/login/index.com
systemctl restart httpd