天天看點

apache服務

apache服務

server端:

yum search http        

yum install httpd.x86_64 -y        ##安裝http服務##

systemctl start httpd        ##開啟http服務##

systemctl  enable httpd        ##開機啟動http服務##

firewall-cmd --list-all        ##檢視火牆的服務開啟狀态##

firewall-cmd --permanent --add-service=http         ##永久開啟http服務##

firewall-cmd --permanent --add-service=https        ##永久開啟https服務##

firewall-cmd --reload        ##重新整理火牆狀态##

firewall-cmd --list-all        

cd /var/www/html        ##apache服務共享檔案的預設目錄##

vim westos.html

            hello world       

測試:firefox輸入server端ip(如:172.25.254.44),則顯示westos.html中的内容

注:輸入後一般預設是http://172.25.254.44,若不是修改則需要修改為http://

apache端口:

apache服務的預設端口為80

vim /etc/httpd/conf/httpd.conf            ##apache服務的主配置檔案## 

40 #

 41 #Listen 12.34.56.78:80

 42 Listen 8080               ##修改預設端口80為8080##

 43

systemctl restart httpd            ##重新開機httpd服務##

firewall-cmd --permanent --add-port=8080/tcp            ##在火牆中永久開啟8080端口##

firewall-cmd --reload

測試:firefox輸入server端ip端口8080(如:172.25.254.44:8080),則顯示westos.html中的内容

apache的主配置檔案:/etc/httpd/conf/httpd.conf 

119 #DocumentRoot "/var/www/html"

120 #

121 DocumentRoot "/www/html"

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

123 #

124 <Directory "/www/html">             ##預設通路目錄為/www/html##

125     AllowOverride None

126     # Allow open access:

127     Require all granted

162 #

163 <IfModule dir_module>

164     DirectoryIndex westos.html linux.html           ##預設先通路westos.html檔案##

165 </IfModule>

cd /var/www/html

vim linux.html

                    welcome to the page

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

            welcome to the page of news

cd /etc/httpd/conf.d

 vim news.conf         ##修改虛拟主機news的配置檔案##

        <Virtualhost *:80>

                 Servername news.westos.com                 ##通路虛拟主機news時的域名##

                 Documentroot /var/www/news  

                  customlog "logs/news.log" combined

        <Directory /var/www/news>

                  require all granted

cd /var/www/music/

vim linux

            welcome to the page of music

cd /etc/httpd/conf.d/

 vim music.conf        ##修改虛拟主機music的配置檔案##

                 Servername music.westos.com                ##通路虛拟主機music時的域名##

                   Documentroot /var/www/music

                  customlog "logs/music.log" combined

        <Directory /var/www/music>

selinux标簽:

semanage fcontext -l

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

restorecon -vvFR /directory

systemctl restart httpd

server端域名解析:

vim /etc/hosts

    172.25.254.44 www.westos.com news.westos.com music.westos.com

測試:

fireworx通路

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

        <Directory /var/www/news/admin>

                  Authuserfile /etc/http/conf/apacheusr               ##使用者密碼檔案目錄##

                  Authname "Please input your name and password"             ##登陸提示##

                  Authtype basic

                  Require valid-user               ##所有可用使用者##

firefox通路news.westos.com/admin

自定義自簽名證書:

yum install mod_ssl -y        

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

        <Directory “/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

上一篇: apache學習
下一篇: Apache配置