Apache

===部署===

#yum install httpd -y

/etc/httpd *****
/etc/httpd/conf/httpd.conf *****
/etc/httpd/conf.d
/etc/httpd/conf.d/welcome.conf
/etc/httpd/logs
/etc/httpd/modules
/etc/rc.d/init.d/httpd
/etc/init.d/httpd ****
/var/www
/var/www/cgi-bin
/var/www/error
/var/www/html *****
/usr/bin/ab
/usr/bin/htpasswd

编辑配置文件

#vi /etc/httpd/conf/httpd.conf

修改监听端口为8080
-------------
Listen 8080
-------------

#编写网站默认索引页
#vi /var/www/html/index.html


尝试使用虚拟主机功能做基于域名的虚拟主机

#vi /etc/httpd/conf/httpd.conf
---------------------
NameVirtualHost 172.16.254.101:80 //基于域名的虚拟主机

<VirtualHost 172.16.254.101:80>
ServerName www.baidu.com //域名
DocumentRoot /var/www/html //访问baidu时显示的页面的存放目录
</VirtualHost>

<VirtualHost 172.16.254.101:80>
ServerName www.google.com //域名
DocumentRoot /var/www/html1 //访问google时显示的页面的存放目录
</VirtualHost>
----------------------
#vi /var/www/html/index.html
#mkdir /var/www/html1
#vi /var/www/html1/index.html
#service httpd restart

每次修改完配置文件以后,都需要重启httpd服务

------------------------------------------------------------
实验中需要用到域名与IP的对应关系

Linux将对应关系写入到/etc/hosts
windows将对应关系写入到c:\windows\system32\drivers\etc\hosts
------------------------------------------------------------
在linux终端模式没有浏览器,可以使用elinks进行测试
#yum install elinks -y
#vi /etc/hosts
172.16.254.101 www.baidu.com
172.16.254.101 www.google.com
#elinks --dump http://www.baidu.com
#elinks --dump http://www.google.com
------------------------------------------------------------

----基于域名的虚拟主机-----
* 只能通过域名来访问服务器
#vi /etc/httpd/conf/httpd.conf
-------------
NameVirtualHost 172.16.254.101:80
<VirtualHost 172.16.254.101:80>
ServerName www.baidu.com
DocumentRoot /var/www/html
</VirtualHost>
<VirtualHost 172.16.254.101:80>
ServerName www.google.com
DocumentRoot /var/www/html1
</VirtualHost>
--------------
需要借助DNS来完成网页的访问


----基于IP的虚拟主机-----
* 服务器需要有多个IP地址
*临时设置一个IP
#ifconfig eth0:0 172.16.X.202 netmask 255.255.0.0
#vi /etc/httpd/conf/httpd.conf
-------------
<VirtualHost 172.16.254.101:80>
ServerName www.baidu.com
DocumentRoot /var/www/html
</VirtualHost>
<VirtualHost 172.16.254.202:80>
ServerName www.google.com
DocumentRoot /var/www/html1
</VirtualHost>
--------------

----基于端口的虚拟主机-----
* 需要在配置文件中添加一条Listen属性

#vi /etc/httpd/conf/httpd.conf
-------------
Listen 80
Listen 8080
<VirtualHost 172.16.254.101:80>
ServerName www.baidu.com
DocumentRoot /var/www/html
</VirtualHost>
<VirtualHost 172.16.254.101:8080>
ServerName www.google.com
DocumentRoot /var/www/html1
</VirtualHost>
--------------

https (http+TLS)

#yum install httpd -y

# openssl genrsa 1024 > web.key //生成私钥
Generating RSA private key, 1024 bit long modulus
...............................................................++++++
..........++++++
e is 65537 (0x10001)
# openssl req -new -key web.key -days 365 -x509 -out web.crt
//生成自签名证书
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) [XX]:CN
State or Province Name (full name) []:liaoning
Locality Name (eg, city) [Default City]:shenyang
Organization Name (eg, company) [Default Company Ltd]:uplooking
Organizational Unit Name (eg, section) []:instructor
Common Name (eg, your name or your server's hostname) []:s1.uplooking.com
Email Address []:zhouxiaoyu@uplooking.com

#yum install mod_ssl -y //httpd支持tls(https)的模块
# vi /etc/httpd/conf.d/ssl.conf //写入将证书与私钥的位置
----------------------------
105 SSLCertificateFile /etc/pki/tls/certs/web.crt //证书的位置
112 SSLCertificateKeyFile /etc/pki/tls/private/web.key //私钥的位置
----------------------------
# cp web.key /etc/pki/tls/private/
# cp web.crt /etc/pki/tls/certs/

# service httpd restart

# netstat -antulp | grep :80
tcp 0 0 :::80 :::* LISTEN 2245/httpd
[root@s1 ~]# netstat -antulp | grep :443
tcp 0 0 :::443 :::* LISTEN 2245/httpd

使用网页浏览器访问https://172.16.254.101

posted @ 2016-08-24 13:56  赤叶  阅读(177)  评论(0编辑  收藏  举报