Apache服务器部署(2)

签名CA证书

环境:server1:172.25.1.1    重置虚拟机       挂载yum源         

[[email protected] ~]# yum install mod_ssl -y                 //下载ssl模块

[[email protected] ~]# yum install crypto-utils -y             //安装加密软件

[[email protected] ~]# genkey www.westos.com           //对www.westos.com加密

Apache服务器部署(2)

Apache服务器部署(2)https://mp.****.net/

这个过程一般比较慢,可以另外打开一个终端,并不断按键或者拖动鼠标

Apache服务器部署(2)

Apache服务器部署(2)

Apache服务器部署(2)

//填写证书内容

Apache服务器部署(2)

//点击Next进行下一步,会出现下面的内容

Apache服务器部署(2)

其中,

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          //**

[[email protected] ~]# vim /etc/httpd/conf.d/ssl.conf                   //修改文件中的证书及**

SSLCertificateFile /etc/pki/tls/certs/www.westos.com.crt

SSLCertificateKeyFile /etc/pki/tls/private/www.westos.com.key

Apache服务器部署(2)

[[email protected] ~]# systemctl restart httpd

此时进行网页浏览:

Apache服务器部署(2)

Apache服务器部署(2)

Apache服务器部署(2)

Apache服务器部署(2)

1、当**生成错误时,进入目录/etc/pki/tls/serts删除证书,进入目录cd /etc/pki/tls/private/删除**

2、若重新生成**后还是不能下载证书则进行Edit–>Advanced–>View并删除本机证书后即可下载。

网页重写

[[email protected] ~]# mkdir /var/www/virtual/westos.com/login -p
[[email protected] ~]# vim /var/www/virtual/westos.com/login/index.html 

Apache服务器部署(2)
[[email protected] ~]# cd /etc/httpd/conf.d/
[[email protected] conf.d]# ls
autoindex.conf  README  ssl.conf  userdir.conf  welcome.conf
[[email protected] conf.d]# vim login.conf

<VirtualHost *:443>        
    ServerName login.westos.com            
    DocumentRoot "/var/www/virtual/westos.com/login/"            //默认发布目录,即网页文件存放位置

    CustomLog "logs/login.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/virtual/westos.com/login/">
    Require all granted
</Directory>
<VirtualHost *:80>
    ServerName login.westos.com
    RewriteEngine on
    RewriteRule ^(/.*)$ https://%{HTTP_HOST}$1 [redirect=301]
</VirtualHost>

Apache服务器部署(2)

由于用户输网址时不会刻意添加加密访问字符‘https://’, 所以我们可以用代码强制将用户输入站点自动跳转到‘https://

    RewriteRule ^(/.*)$ https://%{HTTP_HOST}$1 [redirect=301]

[[email protected] conf.d]# systemctl restart httpd

网页进行访问:

Apache服务器部署(2)

即使访问时没有添加https://但回车时还时会自动添加上

Apache支持PHP语言(已经支持了html)

[[email protected] conf]# pwd
/etc/httpd/conf

[[email protected] conf]# vim httpd.conf

Apache服务器部署(2)

[[email protected] conf]# vim /etc/httpd/conf/httpd.conf                 //配置文件中添加默认发布目录index.php

Apache服务器部署(2)

[[email protected] conf]# yum install php -y             //安装php

[[email protected] conf]# cd /var/www/html/
[[email protected] html]# mkdir cgi                 
[[email protected] html]# cd cgi/
[[email protected] cgi]# vim index.cgi                //写脚本

[[email protected] cgi]# chmod +x index.cgi             //给脚本加可执行权限
[[email protected] cgi]# ./index.cgi               //执行脚本
Content-type: text/html

Sun Mar 10 03:48:04 EDT 2019
[[email protected] cgi]# cd -
/var/www/html
[[email protected] html]# cd /etc/httpd/conf.d/
[[email protected] conf.d]# ls
autoindex.conf  php.conf  ssl.conf      welcome.conf
login.conf      README    userdir.conf
[[email protected] conf.d]# vim default.conf                         
[[email protected] conf.d]# vim /etc/httpd/conf/httpd.conf
[[email protected] conf.d]# systemctl restart httpd

此时在网页进行访问:

Apache服务器部署(2)

论坛的搭建

[[email protected] ~]# systemctl start httpd

[[email protected] ~]# yum install -y mariadb

[[email protected] ~]# yum install mariadb-server

[[email protected] ~]# systemctl start mariadb

下载论坛的安装包至/var/www/html

[[email protected] westos]# cd /var/www/html/
[[email protected] html]# ls
cgi  Discuz_X3.2_SC_UTF8.zip  index.html  index.php
[[email protected] html]# unzip Discuz_X3.2_SC_UTF8.zip
-bash: unzip: command not found
[[email protected] html]# yum intall -y unzip

[[email protected] html]# unzip Discuz_X3.2_SC_UTF8.zip

[[email protected] html]# ls
Apache服务器部署(2)
[[email protected] html]# chmod 777 /var/www/html/upload/ -R            //添加权限
[[email protected] html]# yum install -y php-mysql               //安装php-mysl

[[email protected] html]# systemctl restart httpd

在浏览器中输入http://172.25.1.1/upload/install/

Apache服务器部署(2)

点击index.php

Apache服务器部署(2)

Apache服务器部署(2)

Apache服务器部署(2)

[[email protected] html]# mysql_secure_installation

[[email protected] html]# mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y                            //设置root密码,这里我设置的是redhat
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!

//后面都输入y

返回浏览器:

注意:填写表格时:数据库服务器为localhost 数据库名为root  数据库用户名为root  数据库密码为redhat  管理员密码为admin其他部分不变

Apache服务器部署(2)

Apache服务器部署(2)

此时点击admin.php

Apache服务器部署(2)

提交:

Apache服务器部署(2)

论坛搭建完成

 

正向代理及反向代理  

正向代理:

        也就是在浏览器的网络连接属性框中,填写上一个代理服务器的ip和端口,即可通过代理服务器中转,去浏览网页。有时候网站对单个 IP 某些操作进行了次数限制。它是一个位于客户端和原始服务器之间的服务器,为了从原始服务器取得内容,客户端向代理发送一个请求并指定目标(原始服务器),然后代理向原始服务器转交请求并将获得的内容返回给客户端。客户端才能使用正向代理。

反向代理(Reverse Proxy):

        是指以代理服务器来接受 Internet 上的连接请求,然后将请求转发给内部网络上的服务器,并将从服务器上得到的结果返回给 Internet 上请求连接的客户端,此时代理服务器对外就表现为一个反向代理服务器。常用做网站服务器配置,可以提供从防火墙外部代理服务器到防火墙内部安全内容服务器的加密连接,隐藏后端真实服务器,更加安全。如 负载均衡 ,CDN 缓存都是反向代理。

http与https的区别

超文本传输协议HTTP协议被用于在Web浏览器和网站服务器之间传递信息。HTTP协议以明文方式发送内容,不提供任何方式的数据加密,如果攻击者截取了Web浏览器和网站服务器之间的传输报文,就可以直接读懂其中的信息,因此HTTP协议不适合传输一些敏感信息,比如信用卡号、密码等。

为了解决HTTP协议的这一缺陷,需要使用另一种协议:安全套接字层超文本传输协议HTTPS。为了数据传输的安全,HTTPS在HTTP的基础上加入了SSL协议,SSL依靠证书来验证服务器的身份,并为浏览器和服务器之间的通信加密,实现http的安全数据传输。可以说https就是http的升级版

HTTPS和HTTP的区别主要为以下四点:

一、https协议需要到ca申请证书,一般免费证书很少,需要交费。

二、http是超文本传输协议,信息是明文传输,https 则是具有安全性的ssl加密传输协议。

三、http和https使用的是完全不同的连接方式,用的端口也不一样,前者是80,后者是443。

四、http的连接很简单,是无状态的;HTTPS协议是由SSL+HTTP协议构建的可进行加密传输、身份认证的网络协议,比http协议安全。

apache与nginx的区别

nginx

  1. epoll 异步非阻塞
  2. nginx在开启时,会生成一个master进程,然后,master进程会fork多个worker子进程,最后每个用户的请求由worker的子线程处理。
  3. 可以配置nginx的upstream实现nginx的反向代理;nginx 本身就是一个反向代理服务器,而且可以作为非常优秀的邮件代理服务器。
  4. 支持7层负载均衡,可做为负载均衡器。
  5. 静态文件、反向代理、前端缓存等处理方便;nginx 处理静态文件好,静态处理性能比 apache 高3倍以上
  6. 支持高并发连接,每秒最多的并发连接请求理论可以达到 50000 个
  7. nginx 配置简洁,正则配置让很多事情变得简单,而且改完配置能使用 -t 测试配置有没有问题,apache 配置复杂 ,重启的时候发现配置出错了,会很崩溃
  8. 用线程处理用户请求,而线程是共享内存的,只需要开启少量进程,多个线程就可以共享进程的内存,占用内存小,轻量级,采用 C 进行编写,同样的 web 服务,会占用更少的内存及资源;
  9. 一个进程死掉时,会影响到多个用户的使用,稳定性差
  10. 即使运行数个月也不需要重新启动,还能够不间断服务的情况下进行软件版本的升级
  11. 社区活跃,各种高性能模块出品迅速

apache

  1. apache 的 rewrite 比 nginx 强大,在 rewrite 频繁的情况下,用 apache
  2. 组件比nginx多
  3. 一个连接对应一个进程
  4. 当用户请求过多时,开启的进程较多,占用内存大,每秒最多的并发连接请求最多不超过 3000 个
  5. 一个进程死掉时,不会影响其他的用户;apache 超稳定
  6. apache 发展到现在,模块超多,基本想到的都可以找到
  7. apache 更为成熟,少 bug ,nginx 的 bug 相对较多
  8. apache 在处理动态请求有优势,nginx 在这方面是鸡肋,一般动态请求要 apache 去做,nginx 适合静态和反向。
  9. apache 仍然是目前的主流,拥有丰富的特性,成熟的技术和开发社区

总结:

核心区别在于nginx是异步的,多连接可对应一个进程,而apache是一个连接对应一个进程,同步多进程。