httpd

---恢复内容开始---

 

编译安装httpd2.4

  1  安装依赖包    

[root@centos7 source]# yum install gcc prce-devel openssl-devel expat-devel -y

     

   2   下载对应的解压包

      

      

       3    解压

      出错

        

      解决

        

        全部解压       

[root@centos7 source]# tar xf httpd-2.4.39.tar.bz2 
[root@centos7 source]# tar xf apr-1.7.0.tar.bz2 
[root@centos7 source]# tar xf apr-util-1.6.1.tar.bz2

 

  4   进到解压的httpd目录    

[root@centos7 source]# cd httpd-2.4.39

 

  5  将解压的apr和apr-util移动到srclib目录,并改名 

[root@centos7 httpd-2.4.39]# mv ../apr-1.7.0 ./srclib/apr
[root@centos7 httpd-2.4.39]# mv ../apr-util-1.6.1 ./srclib/apr-util

 

  6 编译安装

[root@centos7 httpd-2.4.39]# ./configure --prefix=/app/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-included-apr --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork
[root@centos7 httpd-2.4.39]# make -j 4 && make install

      7 将启动路径添加到PATH变量

[root@centos7 httpd24]# vim /etc/profile.d/httpd.sh
         
#!/bin/bash
PATH=/app/httpd24/bin:$PATH

[root@centos7 httpd24]# . /etc/profile.d/httpd.sh

   

  8  启动并且设置开机自启动

[root@centos7 httpd24]# apachectl start


[root@centos7 httpd24]# vim /etc/rc.d/rc.local

# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local
/app/httpd24/bin/apachectl start



[root@centos7 httpd24]# chmod +x /etc/rc.d/rc.local 

 

基于虚拟主机

  1  编辑配置文件,将这一行注释取消

[root@node3 conf]#vim /app/httpd24/conf/httpd.conf

Include conf/extra/httpd-vhosts.conf   

  2  添加虚拟主机

[root@node3 conf]#vim /app/httpd24/conf/extra/httpd-vhosts.conf

<VirtualHost*:80>                                                                                                                                  
          DocumentRoot "/data/admin/"
          ServerName www.a.com
          ErrorLog "logs/dummy-host2.example.com-error_log"
          CustomLog "logs/dummy-host2.example.com-access_log" common
          <Directory "/data/admin">
          Require all granted
         </Directory>
</VirtualHost>

  3  创建/data/admin

[root@node3 conf]#mkdir /data/admin/
[root@node3 conf]#vim /data/admin/index.html
this is a server

  4  重启服务

[root@node3 conf]#apachectl restart

 

实现压缩

  1   在虚拟主机中添加压缩模块

[root@node3 extra]#vim httpd-vhosts.conf

<VirtualHost *:80>                                                                                                                                  
          DocumentRoot "/data/admin/"
          ServerName www.a.com
          ErrorLog "logs/dummy-host2.example.com-error_log"
          CustomLog "logs/dummy-host2.example.com-access_log" common
          <Directory "/data/admin">
          Require all granted 
         </Directory>
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/css

DeflateCompressionLevel 9                                                                                                                           
</VirtualHost>

  2  重启服务

[root@node3 admin]#apachectl restart

 

实现https

  1    创建ca 申请证书(我这里用的脚本)

       2   修改配置文件    

 
[root@node3 conf]#vim httpd.conf

 


[root@node3 extra]#vim httpd-ssl.conf listen 443 <VirtualHost *:443> DocumentRoot "/data/ssl" <directory "/data/ssl"> require all granted </directory> ServerName www.a.com SSLEngine on SSLCertificateFile "/app/httpd24/conf/extra/ssl/httpd.crt" SSLCertificateKeyFile "/app/httpd24/conf/extra/ssl/httpd.key" SSLCACertificateFile "/app/httpd24/conf/extra/ssl/cacert.pem" </VirtualHost>

 

  3   重启出错

    

           解决方法,编辑配置文件,启动ssl模块 

[root@node3 conf]#vim httpd.conf

       4   启动

 

 

实现http到https重定向

  1 打开模块 

[root@node3 extra]#vim ../httpd.conf
#LoadModule slotmem_shm_module modules/mod_slotmem_shm.so
LoadModule ssl_module modules/mod_ssl.so 

 

  2 修改配置文件

[root@node3 extra]#vim httpd-vhosts.conf
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/x-httpd-php
AddOutputFilterByType DEFLATE image/svg+xml  
Redirect temp
/ https://www.a.com/ </VirtualHost>

      3 重启服务

 

实现HSTS

  1  打开模块

[root@node3 extra]#vim ../httpd.conf
#LoadModule slotmem_shm_module modules/mod_slotmem_shm.so
LoadModule ssl_module modules/mod_ssl.so 

  2 修改配置文件

[root@node3 extra]#vim httpd-vhosts.conf
AddOutputFilterByType DEFLATE application/x-httpd-php AddOutputFilterByType DEFLATE image/svg+xml RewriteEngine on RewriteRule ^(/.*)$ https://%{HTTP_HOST}$1 [redirect=302] </VirtualHost>

       3 重启

 

 

 

 

    

 

---恢复内容结束---

posted @ 2019-07-24 15:18  Linus小跟班  阅读(274)  评论(0编辑  收藏  举报