码迷,mamicode.com
首页 > Web开发 > 详细

Apache2.4 企业七简单配置

时间:2017-08-16 23:11:25      阅读:382      评论:0      收藏:0      [点我收藏+]

标签:linux   运维   基础学习   

1、Apache服务安装

[root@server ~]# yum install httpd  -y
[root@server ~]# systemctl restart httpd
[root@server ~]# systemctl stopfirewalld.service

安装完成之后你可以打开你的浏览器,在网址部分输入172.25.254.231(也就是你本机的IP),会出现Apache的默认页面。

技术分享

2. 修改站点目录和为站点目录增加密要

2.1 生成密钥

[root@server conf]#  htpasswd -cm authfile admin
New password:
Re-type new password:
Adding password for user admin
[root@server conf]#  htpasswd -m authfile admin1
#如果出现authfile这个文件如果在添加用户认证,则不需要增加-c参数。,
New password:
Re-type new password:
Adding password for user admin1

3.2 修改站点目录

[root@server conf]#   vim /etc/httpd/conf/httpd.conf
119 #DocumentRoot "/var/www/html"
注释掉上面默认的站点目录DocumentRoot ,添加一行新的站点目录。
120 DocumentRoot"/test/lala/html"
添加新的站点目录/test/lala/html
130 <Directory"/test/lala/html">
131# Require all granted
#允许任何人访问站点目录,在做这个实验时,需要将他注释掉
132 AuthUserFile /etc/httpd/conf/authfile
#添加一个密码认证
133 AuthName "please input you countand password"
#在登陆网址时的提示语
134 AuthType basic
#为基础认证
135 Require user admin
#当注释掉136行,只能使用admin密钥
#当注释掉135行,使用任意密钥都可以登陆
136 Require valid-user
137 </Directory>
这时如果在访问目录则会出现如下页面,让你输入密码

3.3 修改站点目录的上下文

[root@server html]# semanage  fcontext -a -t  httpd_sys_content_t ‘/test(/.*)?‘
[root@server html]# restorecon  -RvvF /test
restorecon reset /test contextunconfined_u:object_r:default_t:s0->system_u:object_r:httpd_sys_content_t:s0
restorecon reset /test/lala contextunconfined_u:object_r:default_t:s0->system_u:object_r:httpd_sys_content_t:s0
restorecon reset /test/lala/html contextunconfined_u:object_r:default_t:s0->system_u:object_r:httpd_sys_content_t:s0
restorecon reset /test/lala/html/index.ht

如果这时你如果在访问就会出现如下界面,让你输入密码:

技术分享

3.改默认的站点目录的文件

[root@server ~]# vim/etc/httpd/conf/httpd.conf

<IfModule dir_module>
  DirectoryIndexfei.html index.html
  #注意以空格隔开,从前往后,先找你的fei.html,在找你的index.html
</IfModule>

4.虚拟主机的配置

4.1 在主配置文件中添加虚拟主机

  在主配置文件中添加如下内容:

[root@server ~]# vim/etc/httpd/conf/httpd.conf
<Virtualhost *:80>
  Servername www.fei.com
  DocumentRoot /var/www/fei/
  CustomLog "logs/fei.log" combined
</Virtualhost>

<Directory "/var/www/fei">
  Require all granted
</Directory>
  #下面是另一个虚拟主机的配置文件
<Virtualhost *:80>
  Servername www.tian.com
  DocumentRoot /var/www/tian/
  CustomLog "logs/tian.log"combined
</Virtualhost>

<Directory "/var/www/tian">
  Require all granted
</Directory>

  分别建立2个目录为 /var/www/fei//var/www/tian/,分别为两个虚拟主机的站点目录,在下面建立fei.html 或者index.html,因为我们在前面添加了fei.index。

[root@server html]# mkdir /var/www/fei
[root@server html]# mkdir /var/www/tian
[root@server fei]# cat  /var/www/tian/index.html
this is tian‘s virtulhost
[root@server fei]# cat  /var/www/fei/index.html
this is fei‘s virtulhost
#在/etc/hosts中添加如下内容,增加本地DNS解析。
[root@server ~]# vim /etc/hosts
172.25.254.231 www.fei.com  www.tian.com

4.2 在/etc/httpd/conf.d下面添加虚拟主机

  还有一个添加虚拟主机的方法:分别在这个目录下建立3个不同的文件分别为默认站点目录和两个虚拟主机的站点目录

[root@server conf.d]# pwd
/etc/httpd/conf.d
#这个是 虚拟主机的配置文件 
[root@server conf.d]# vim fei.conf
<Virtualhost *:80>
  Servername www.fei.com
  DocumentRoot /var/www/fei/
  CustomLog "logs/fei.log" combined
</Virtualhost>

<Directory "/var/www/fei">
 Require all granted
</Directory>     
#下面是www.tain.com的默认主机配置文件              
[root@server conf.d]# vim  tian.conf
<Virtualhost *:80>
  Servername www.tian.com
  DocumentRoot /var/www/tian/
  CustomLog "logs/tian.log"combined
</Virtualhost>

<Directory "/var/www/tian">
 Require all granted
</Directory>
#这个是默认的配置文件,也就是你输入172.25.254.231是访问的页面
[root@server conf.d]# vim default.conf
<Virtualhost _default_:80>
 DocumentRoot "/var/www/html/"
 CustomLog "logs/default.log" combind
</Virtualhost>
#注意:配置文件可以在两个地方写,下面的做法也是建立虚拟主机的目录,写index.html文件。

技术分享技术分享

5.https 的配置

5.1 软件安装

yum install mod_ssl  -y
#安装https插件,使你的apache支持https.
yuminstall crypto-utils.x86_64  -y
#安装插件生成钥匙和锁

5.2 生成证书

[root@server ~]# genkey www.westos.com
/usr/bin/keyutil -c makecert -g 1024 -s"CN=www.westos.com, OU=linux, O=westos, L=xi‘an, ST=Shannxi, C=CN" -v1 -a -z /etc/pki/tls/.rand.3669 -o /etc/pki/tls/certs/www.westos.com.crt -k/etc/pki/tls/private/www.westos.com.key
cmdstr: makecert
cmd_CreateNewCert
command: makecert
keysize = 1024 bits
subject = CN=www.westos.com, OU=linux,O=westos, L=xi‘an, ST=Shannxi, C=CN
valid for 1 months
random seed from /etc/pki/tls/.rand.3669
output will be written to/etc/pki/tls/certs/www.westos.com.crt
output key written to/etc/pki/tls/private/www.westos.com.key
Generating key. This may take a fewmoments...
Made a key
Opened tmprequest for writing
/usr/bin/keyutil Copying the cert pointer
Created a certificate
Wrote 882 bytes of encoded data to/etc/pki/tls/private/www.westos.com.key
Wrote the key to:
/etc/pki/tls/private/www.westos.com.key

  这个页面是我们要填写的证书信息,还有要注意的是在生成证书过程中不要想CN认证发你的证书,这个是收费的。

技术分享

5.2 修改http配置文件

    我的虚拟主机在主配置文件中,所以我要修改主配置文件中的虚拟主机配置

[root@server ~]# vim /etc/httpd/conf/httpd.conf
<Virtualhost *:443>
  #将这个虚拟网站的端口改为434,因为HTTPS服务的端口在434
  Servername www.fei.com
  DocumentRoot /var/www/fei/
  CustomLog "logs/fei.log" combined
  SSLEngine on
  SSLCertificateFile  /etc/pki/tls/certs/www.westos.com.crt  #认证证书
  SSLCertificateKeyFile /etc/pki/tls/private/www.westos.com.key  #钥匙
</Virtualhost>
#下面是对网站的授权,允许任何人访问
<Directory "/var/www/fei">
 Require all granted 
</Directory>
#下面是对网站的二次更改
<virtualhost *:80> 
  ServerName www.fei.com
  RewriteEngine on
  RewriteRule ^(/.*)$ https://%{HTTP_HOST}$1[redirect=301]
</virtualhost>

5.3 修改https的配置文件

[root@server ~]# vim/etc/httpd/conf.d/ssl.conf
101 SSLCertificateFile  /etc/pki/tls/certs/www.westos.com.crt
109 SSLCertificateKeyFile/etc/pki/tls/private/www.westos.com.key

  这时你在访问www.fei.com, 现如下页面自动将其转换为HTTPS协议加密传输

技术分享

  点击I Understand rhe Risks,然后点击Add Execption

技术分享

  出现如下页面,点击 Get Certificate,然后在点击Confirm Security Exception,就会出现如下页面,也就是我们配置好的虚拟主机的页面,不过他是https

技术分享

  我们的认证证书信息也可以查看如下图

技术分享

6.Apache 正向代理

6.1 修改你的server和client的网卡

修改你server的ip为其添加另一块网卡为eth1
Server 的网卡分别为etho:172.25.254.231 eth1 172.25.31.231
Client的网卡ehh0:172.25.31.131

6.2 安装代理软件

  在server 安装代理软件

[root@client ~]# yum install  squid -y
[root@server ~]# vim /etc/squid/squid.conf
 56 http_access allow all
 62 cache_dir ufs /var/spool/squid 100 16 256
[root@server ~]# systemctl restart squid

  打开你的浏览器修改你的高级网络配置

技术分享

这时你的client就可以通过server访问client访问不到的172.25.254网段的Apache。

7. http 反向代理(需要3)

   清除你浏览器中正向的设置,然后配server中的配置文件

[root@server ~]# vim /etc/squid/squid.conf
 56http_access allow all
 59http_port 80 vhost vport
 60cache_peer 172.25.254.117 parent 80  0proxy-only
 #第三台服务器的ip
 62cache_dir ufs /var/spool/squid 100 16 256

关闭你serverapache,这时你用虚拟机访问172.25.31.231时就会访问到172.25.254.117的站点。


本文出自 “13122323” 博客,请务必保留此出处http://13132323.blog.51cto.com/13122323/1956866

Apache2.4 企业七简单配置

标签:linux   运维   基础学习   

原文地址:http://13132323.blog.51cto.com/13122323/1956866

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!