自己没事会整理一些小知识,复习原来的同时也帮助新手。

vvvvvvvvvvvvv开启apache目录验证vvvvvvvvvvvvvv

htpasswd -cm uers redhat   //redhat用户是虚拟的用户uers为生成加密用户的密码文件

# htpasswd -cm uers redhat   //第二次这样输入它会把第一次的输入覆盖掉

[root@redhat httpd]# cat uers

redhat:$apr1$8X/YcAoY$xlwRboAtWudU26krVPoyD1

# htpasswd -m uers westos //少个c就不会覆盖原先的

[root@redhat httpd]# cat uers

redhat:$apr1$8X/YcAoY$xlwRboAtWudU26krVPoyD1

westos:$apr1$HUl2zxD9$CI2YcuhNO68hEqch3ttMn1

编辑Apache的配置文件

<Directory "/var/www/html/admin">

AllowOverride ALL

authuserfile "/etc/httpd/uers"

authname "input your name "

authtype basic

require valid-user   //指的是所有用户

#  require user admin  //这个指的是单个用户

</Directory>

测试时ip+admin(目录)

vvvvvvvvvvvvvvapache虚拟主机的配置vvvvvvvvvvvvvvvvv

cd /var/www //2个发布目录

# mkdir html1

# cd html1/

vim index.html

/var/www/html

vim index.html

apache的配置文件

NameVirtualHost *:80   //打开80端口

<VirtualHost *:80>  //配置apche的配置文件

DocumentRoot /var/www/html  //这个是Apache默认发布目录

ServerName redhat.example.com

ErrorLog logs/redhat.example.com-error_log

CustomLog logs/redhat.example.com-access_log common

</VirtualHost>

<VirtualHost *:80>

DocumentRoot /var/www/html1 //这个目录和上面那个不是一个目录,看清这个是“html1”

ServerName www.example.com

ErrorLog logs/www.example.com-error_log

CustomLog logs/www.example.com-access_log common

</VirtualHost>

客户端

# vim /etc/hosts

192.168.3.30   redhat.example.com

192.168.3.30    www.example.com 在浏览器中分别输入redhat.example.com   www.example.com域名

vvvvvvvvvvvvvvvvvvvvApache加密证书的制作vvvvvvvvvvvvvvvvvvvvvvvvvvv

# yum install mod_ssl -y  //按装mod_ssl软件包

/etc/pki/tls/private

# rm -rf localhost.key   //默认安装好软件包回生成一对私钥

/etc/pki/tls/certs

# rm -rf localhost.crt  //删除公钥

# make localhost.crt //自己生成一对公私钥

localhost.crt   localhost.key

# /etc/init.d/httpd restart //重启apche服务会提示输入密码

Enter pass phrase:

# openssl --help

# openssl genrsa 1024

# openssl genrsa 1024 > localhost.key //导出私钥

# make localhost.crt  //编辑公钥

# /etc/init.d/httpd restart  //重启系统发现不会提示让你输入密码

https://www.example.com/

redhat.example.com

https://redhat.example.com/   //发现不同的域名访问到的内容是相同的,说明虚拟主机有问题 redhat.example.com

/etc/httpd/conf.d/  //配置ssl.conf它所使用的端口为443

# vim ssl.conf

NameVirtualHost *:443   //写在ssl文件中的其实就是Apache虚拟主机的内容,port由80变为443,只是多了带色的那几行,仅此而已

<VirtualHost *:443>

SSLEngine on

SSLCertificateFile /etc/pki/tls/certs/localhost.crt

SSLCertificateKeyFile /etc/pki/tls/private/localhost.key

DocumentRoot /var/www/html

ServerName redhat.example.com

ErrorLog logs/redhat.example.com-error_log

CustomLog logs/redhat.example.com-access_log common

</VirtualHost>

<VirtualHost *:443>

SSLEngine on

SSLCertificateFile /etc/pki/tls/certs/localhost.crt

SSLCertificateKeyFile /etc/pki/tls/private/localhost.key

DocumentRoot /var/www/html1

ServerName www.example.com

ErrorLog logs/www.example.com-error_log

CustomLog logs/www.example.com-access_log common

</VirtualHost>

# /etc/init.d/httpd restart

客户端测试

https://www.example.com/

www.example.com

https://redhat.example.com/

redhat.example.com

<Apache服务的搭建"三件套"《目录验证》《虚拟主机》《加密证书》>的更多相关文章

  1. 简单物联网:外网访问内网路由器下树莓派Flask服务器

    最近做一个小东西,大概过程就是想在教室,宿舍控制实验室的一些设备. 已经在树莓上搭了一个轻量的flask服务器,在实验室的路由器下,任何设备都是可以访问的:但是有一些限制条件,比如我想在宿舍控制我种花 ...

  2. 利用ssh反向代理以及autossh实现从外网连接内网服务器

    前言 最近遇到这样一个问题,我在实验室架设了一台服务器,给师弟或者小伙伴练习Linux用,然后平时在实验室这边直接连接是没有问题的,都是内网嘛.但是回到宿舍问题出来了,使用校园网的童鞋还是能连接上,使 ...

  3. 外网访问内网Docker容器

    外网访问内网Docker容器 本地安装了Docker容器,只能在局域网内访问,怎样从外网也能访问本地Docker容器? 本文将介绍具体的实现步骤. 1. 准备工作 1.1 安装并启动Docker容器 ...

  4. 外网访问内网SpringBoot

    外网访问内网SpringBoot 本地安装了SpringBoot,只能在局域网内访问,怎样从外网也能访问本地SpringBoot? 本文将介绍具体的实现步骤. 1. 准备工作 1.1 安装Java 1 ...

  5. 外网访问内网Elasticsearch WEB

    外网访问内网Elasticsearch WEB 本地安装了Elasticsearch,只能在局域网内访问其WEB,怎样从外网也能访问本地Elasticsearch? 本文将介绍具体的实现步骤. 1. ...

  6. 怎样从外网访问内网Rails

    外网访问内网Rails 本地安装了Rails,只能在局域网内访问,怎样从外网也能访问本地Rails? 本文将介绍具体的实现步骤. 1. 准备工作 1.1 安装并启动Rails 默认安装的Rails端口 ...

  7. 怎样从外网访问内网Memcached数据库

    外网访问内网Memcached数据库 本地安装了Memcached数据库,只能在局域网内访问,怎样从外网也能访问本地Memcached数据库? 本文将介绍具体的实现步骤. 1. 准备工作 1.1 安装 ...

  8. 怎样从外网访问内网CouchDB数据库

    外网访问内网CouchDB数据库 本地安装了CouchDB数据库,只能在局域网内访问,怎样从外网也能访问本地CouchDB数据库? 本文将介绍具体的实现步骤. 1. 准备工作 1.1 安装并启动Cou ...

  9. 怎样从外网访问内网DB2数据库

    外网访问内网DB2数据库 本地安装了DB2数据库,只能在局域网内访问,怎样从外网也能访问本地DB2数据库? 本文将介绍具体的实现步骤. 1. 准备工作 1.1 安装并启动DB2数据库 默认安装的DB2 ...

  10. 怎样从外网访问内网OpenLDAP数据库

    外网访问内网OpenLDAP数据库 本地安装了OpenLDAP数据库,只能在局域网内访问,怎样从外网也能访问本地OpenLDAP数据库? 本文将介绍具体的实现步骤. 1. 准备工作 1.1 安装并启动 ...

随机推荐

  1. WCF关于VS2010的配置

    C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE 下的 devenv.exe.config 在 <configura ...

  2. Java核心技术卷二部分笔记

    第1章 流与文件 1.2 文本输入与输出 第3章 网络 3.3 可中断套接字 第4章 数据库编程 4.5.2 读写LOB 4.6 可滚动和可更新的结果集 4.8 元数据 第6章 高级Swing 6.1 ...

  3. 转:《JavaScript—之对象参数的引用传递》

    转自:博客园 Wayou http://www.cnblogs.com/Wayou/p/javascript_arguments_passing_with_reference.html 变量 1.Ja ...

  4. windows下使用代理连接github

    在公司的windows下使用github,因为github被墙,查了查,发现给在windows下的git制定代理很简单,一句话   git config --global http.proxy htt ...

  5. initrd映像文档的作用和制作

    1.http://pan.baidu.com/s/1dDrGeKL 2.http://wenku.baidu.com/link?url=qPa_jfkEZCbERnwMYWLwm9EZJ_ebMRJA ...

  6. LeetCode4 Median of Two Sorted Arrays

    题目: There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the ...

  7. 通过GCD、NSOperationQueue队列、NSThread三种方法来创建多线程

    #import "ViewController.h" @interface ViewController () @property (weak, nonatomic) IBOutl ...

  8. mvc3.0 +linq 操作数据库中表的数据(ps:本人菜鸟刚学)

    1:添加控制器类文件HomeController.cs其代码如下: using System; using System.Collections.Generic; using System.Linq; ...

  9. [Java] 两种发起POST请求方法,并接收返回的响应内容的处理方式

    1.利用apache提供的commons-httpclient-3.0.jar包 代码如下: /** * 利用HttpClient发起POST请求,并接收返回的响应内容 * * @param url ...

  10. 如何将你自己的Python package发布到PyPI上

    零.前言 最近做了一个小工具,查询IP或者域名的归属地.做完之后想发布到PyPI上,这样大家就可以通过pip来安装了. 在发布的过程中遇到了一些问题,也学到了很多东西.记录到这篇文章中.希望对大家有所 ...