安装apache2虚拟主机并支持ssl(debian)

简介:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
我的博客已迁移到xdoujiang.com请去那边和我交流
debian下安装apache2+ssl支持
 
一、虚拟主机
1、当前版本
cat  /etc/debian_version 
5.0.1
 
2、本机ip
ifconfig | awk  - v  RS= "Bcast:"  '{print $NF}' | awk  -F:  '/addr/{print $2}'
10.1.10.250
 
3、安装apache2的prefork模式
apt-get -y  install  apache2-mpm-prefork
apache2 -l| grep  prefork.c
   prefork.c
 
4、支持php
apt-get -y  install  php5-cli
apt-get -y  install  libapache2-mod-php5
 
5、修改虚拟主机监听地址和端口 
cat  /etc/apache2/ports .conf
NameVirtualHost 10.1.10.250:80
Listen 10.1.10.250:80
 
6、我这里准备的是aaa.bbb.com域名(配置里注释掉的目前不用 根据情况使用 所以保留着)
cat  /etc/apache2/sites-available/aaa .bbb.com
<VirtualHost 10.1.10.250:80>
     ServerAdmin webmaster@localhost
     ServerName aaa.bbb.com
     DocumentRoot  /var/www
     <Directory />
         Options FollowSymLinks
         AllowOverride None
     < /Directory >
     <Directory  /var/www/ >
         Options -Indexes FollowSymLinks MultiViews
         AllowOverride None
         Order allow,deny
         allow from all
     < /Directory >
#   ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
#   <Directory "/usr/lib/cgi-bin">
#       AllowOverride None
#       Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
#       Order allow,deny
#       Allow from 127.0.0.1 localhost 10.1.0.0/24
#   </Directory>
     ErrorLog  /var/log/apache2/aaa .bbb.com_error.log
     # Possible values include: debug, info, notice, warn, error, crit,
     # alert, emerg.
     LogLevel warn
     CustomLog  /var/log/apache2/aaa .bbb.com_access.log combined
Alias  /jimmy  /var/www/ccc/
<Directory  /var/www/ccc/ >
AllowOverride FileInfo AuthConfig Limit Indexes
Options MultiViews SymLinksIfOwnerMatch IncludesNoExec
<Limit GET POST OPTIONS PROPFIND>
Order Allow,Deny
Allow from 10.0.0.0 /8
#AuthName "by Restricted Area"
#AuthType basic
#AuthUserFile /etc/apache2/securepw
#require user www61com
< /Limit >
<LimitExcept GET POST OPTIONS PROPFIND>
Order deny,allow
Deny from all
< /LimitExcept >
< /Directory >
< /VirtualHost >
 
7、创建网站目录ccc
mkdir  /var/www/ccc  -p
 
8、创建1个php测试文件   
cat  /var/www/ccc/test .php
<?php
phpinfo();
?>;  
 
9、激活站点
cd  /etc/apache2/sites-available
a2ensite aaa.bbb.com 
Enabling site aaa.bbb.com.
Run  '/etc/init.d/apache2 reload'  to activate new configuration!
 
10、修改 /etc/hosts 在最后添加二行
cat  /etc/hosts
10.1.10.250 aaa.bbb.com
aaa.bbb.com 10.1.10.250
 
11、根据情况修改php配置文件(可以不修改)
cat  /etc/php5/apache2/php .ini
expose_php = Off             #关闭版本号 
display_errors = Off         #不显示错误 
log_errors on                #提供错误日志
 
12、全部配置完后需要重启apache2
/etc/init .d /apache2  restart
 
13、使用域名访问测试
如果在windows机器上测试的话 可以修改hosts我这边修改过了
访问aaa.bbb.com /ccc/test .php就可以看到以下图片了

wKioL1V5bPbDVAWUAAFL7vJjcNI649.jpg

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
二、支持ssl
1、建立ssl目录
mkdir  /etc/apache2/ssl  -p
 
2、创建一个证书(时间365天)并填写相关一些信息
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout  /etc/apache2/ssl/aaa .bbb.com.key -out  /etc/apache2/ssl/aaa .bbb.com.crt 
Generating a 2048 bit RSA private key
......+++
....+++
writing new private key to  '/etc/apache2/ssl/aaa.bbb.com.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter  '.' , the field will be left blank.
-----
Country Name (2 letter code) [AU]:cn
State or Province Name (full name) [Some-State]:sh
Locality Name (eg, city) []:shanghai
Organization Name (eg, company) [Internet Widgits Pty Ltd]:aaa
Organizational Unit Name (eg, section) []:aaa
Common Name (eg, YOUR name) []:aaa
Email Address []:aaa@163.com
 
3、aaa.bbb.com的ssl域名
cat  /etc/apache2/sites-available/aaa .bbb.com-ssl
<VirtualHost 10.1.10.250:443>
     ServerAdmin webmaster@localhost
     ServerName aaa.bbb.com
     SSLEngine On
     SSLCertificateKeyFile  /etc/apache2/ssl/aaa .bbb.com.key
     SSLCertificateFile  /etc/apache2/ssl/aaa .bbb.com.crt
Alias  /jimmy  /var/www/ccc/
     <Directory  /var/www/ccc/ >
         Options FollowSymLinks +Execcgi
         AllowOverride None 
         Order deny,allow
         Deny from all
         Allow from 10.0.0.0 /8
     < /Directory >
     
     ErrorLog  /var/log/apache2/aaa .bbb.com_ssl.error.log
     # Possible values include: debug, info, notice, warn, error, crit,
     # alert, emerg.
     LogLevel warn
     CustomLog  /var/log/apache2/aaa .bbb.com_ssl.access.log combined
< /VirtualHost >
 
4、开启ssl模块支持
cd  /etc/apache2/mods-available
a2enmod ssl
Enabling module ssl.
See  /usr/share/doc/apache2 .2-common /README .Debian.gz on how to configure SSL and create self-signed certificates.
Run  '/etc/init.d/apache2 restart'  to activate new configuration!
 
5、开启aaa.bbb.com-ssl站点
cd  /etc/apache2/sites-available
a2ensite aaa.bbb.com-ssl 
Enabling site aaa.bbb.com-ssl.
Run  '/etc/init.d/apache2 reload'  to activate new configuration!
 
6、配置443端口
cat  /etc/apache2/ports .conf 
NameVirtualHost 10.1.10.250:80
Listen 10.1.10.250:80
NameVirtualHost 10.1.10.250:443
<IfModule mod_ssl.c>
     # SSL name based virtual hosts are not yet supported, therefore no
     # NameVirtualHost statement here
     Listen 10.1.10.250:443
< /IfModule >
 
7、全部配置完后需要重启apache2
/etc/init .d /apache2  restart
 
8、查看监听端口
netstat  -tupnl | grep  apache2
tcp        0      0 10.1.10.250:80          0.0.0.0:*               LISTEN      5460 /apache2    
tcp        0      0 10.1.10.250:443         0.0.0.0:*               LISTEN      5460 /apache2 
 
9、使用域名访问测试
如果在windows机器上测试的话 可以修改hosts我这边修改过了
访问https: //aaa .bbb.com /ccc/test .php就可以看到以下图片了

wKiom1V5a23ilMvDAAI9kiDVhvY001.jpg

wKiom1V5a4DjLExPAAEABjqJ1ls956.jpg

1
2
三、参考文档
http: //httpd .apache.org /docs/2 .2/









本文转自 xdoujiang 51CTO博客,原文链接:http://blog.51cto.com/7938217/1660979,如需转载请自行联系原作者
相关实践学习
基于函数计算快速搭建Hexo博客系统
本场景介绍如何使用阿里云函数计算服务命令行工具快速搭建一个Hexo博客。
目录
相关文章
|
1月前
|
网络安全 Apache
Apache服务器安装SSL证书
Apache服务器安装SSL证书
30 0
|
4月前
|
消息中间件 Kubernetes NoSQL
Debian11系统boost库安装
Debian11系统boost库安装
|
3天前
|
安全 Linux 定位技术
Debian安装和基本使用
Debian安装和基本使用
7 0
|
10天前
|
资源调度 JavaScript Ubuntu
Yarn介绍及快速安装Debian/Ubuntu Linux
现在,你已经成功安装了Yarn,可以在你的JavaScript项目中使用它来管理依赖。
49 3
|
13天前
|
SQL 关系型数据库 数据库
如何在 Debian 12 上安装 PostgreSQL?
【4月更文挑战第25天】
29 0
|
20天前
|
存储 Linux 网络安全
如何通过安装XRDP在Debian 12上启用RDP功能
要在 Debian 12 Linux 上启用 RDP 功能,我们需要安装一些第三方软件,例如 XRDP。这将允许 Windows 用户使用内置的远程桌面软件访问远程运行的 Debian。按照本教程,准确了解如何做到这一点......
128 0
|
27天前
|
监控 Shell 开发工具
Debian安装与基本使用:详细指南及常见问题解析
【4月更文挑战第13天】本文档介绍了Debian的安装步骤、基本使用、问题解析及进阶技巧。首先,安装Debian涉及下载ISO镜像,制作启动介质,设置BIOS,然后进行安装过程,包括选择语言、分区、网络配置、软件包选择和用户账户设置。安装完成后,学会基本操作,如命令行使用、软件管理(apt)、系统更新和维护。遇到问题时,解决无线网络、分辨率、输入法和依赖问题。进阶技巧包括自定义Shell环境、使用虚拟化技术(Docker、LXC/LXD)、系统监控与性能调优,以及Git和自动化脚本的高级应用。通过学习这些技巧,可提升在Debian系统上的工作效率。
25 0
|
1月前
|
Kubernetes 安全 API
debian11 安装 k8s,containerd ,阿里云镜像(已成功)
在准备 Kubernetes 集群环境中,确保每台机器至少有 2GB RAM,推荐 4GB,需连接网络。需3台机器,1台作为 Master,2台作为 Worker。安装 `sudo`,设置各节点主机名为 k8s-master、k8s-node1、k8s-node2,并更新 `/etc/hosts`。升级系统,接着安装并更新 containerd 至 v1.7,配置 `containerd` 并启用。
62 0
|
2月前
|
前端开发 应用服务中间件 网络安全
http转为https,ssl证书安装及nginx配置
http转为https,ssl证书安装及nginx配置
58 1
|
3月前
|
SQL 存储 数据安全/隐私保护