xuyaxiu 发表于 2018-11-19 11:26:27

运维学习笔记Apache服务

Apache HTTP SERVER
  Apache软件基金会的一个开放源代码的网页服务器软件
  curl -I 查看网站的网页服务器类型
  实验测试之前注意向发起访问请求的主机添加域名解析/etc/host
一、安装httpd
  yum install httpd
  systemctl start httpd
  systemctl enable httpd #开机启动
  firewall-cmd--permanent --add-service=http #将http服务添加至防火墙列表中
  firewall-cmd--reload
  firewall-cmd--permanent --add-service=https #将https服务添加至防火墙列表中
  firewall-cmd--reload
  修改http的主配置文件修改默认设置
  /etc/httpd/conf/httpd.conf
  42 Listen 80#修改http服务的默认网络端口
  119 DocumentRoot "/www/html"#修改http服务的默认发布目录
  120
  121   Require all granted
  122
  167
  168   DirectoryIndex webtest index.html#默认发布文件,先读前者,前者不可用再读后者#
  169
  firewall-cmd --add-port=8080/tcp
  systemctl restart httpd
  mkdir /www/html/webtest
  selinux标签与默认发布目录一致
  ls -Z /var/www/
  semanage fcontext -a -t httpd_sys_content_t “/www(/.*)?”
  restorecon -vvFR /www
二、虚拟主机
  一台主机为多个网站提供服务
  vim /etc/httpd/conf.d/default.conf
  
        Documentroot /www/html
        Customlog "logs/default.log" combined#指定日志
  
  vim /etc/httpd/conf.d/news.conf
  
        Servername news.laosiji.com
        Serveralias news#设置别称
        Documentroot /www/laosiji.com/news
        Customlog "logs/news.log" combined
  
  
        Require all granted
  
  vim /etc/httpd/conf.d/xxx.conf
  mkdir -p /www/laosiji.com/news
  vim /www/laosiji.com/news/webtest#与前面设置的文件名称一致
三、授权指定用户访问
  首先新建一个发布目录作为测试目录
  mkdir -p /www/laosiji.com/admin/webtest
  htpasswd -cm /etc/httpd/htpasswd admin    #再次添加用户时注意,选项为-m,否则之前的信息会被覆盖
  New password:
  Re-type new password:
  会生成加密密码文件/etc/httpd/htpasswd
  
        Authuserfile "/etc/httpd/htpasswd"
        Authtype basic
        Authname "Please input username and password"
        Require user admin#或者设置为valid-user所有授权用户可登陆
  
四、自定义自签名证书
  yum install crypto-utils mod_ssl
  genkey laosiji.com #主机名,生成证书
  


  选择next


  有几种密钥规格供选择


  生成密钥中    #生成缓慢时可以敲击键盘或移动鼠标


  选择no不向CA发送验证请求


  选择next


  填写一些信息(注意主机名不要写错)
  vim /etc/httpd/conf.d/login.conf#新建login用于测试
  mkdir /www/laosiji.com/login
  
        Servername login.laosiji.com
        Serveralias login
        Documentroot /www/laosiji.com/login
        Customlog "logs/login.log" combined
        SSLEngine on
        SSLCertificateFile /etc/pki/tls/certs/laosiji.com.crt
        SSLCertificateKeyFile /etc/pki/tls/private/laosiji.com.key
  
  
        Require all granted
  
  #网页重定向
  servername login.laosiji.com
  rewriteengine on
  rewriterule ^(/.*)$ https://%{HTTP_HOST}$1
  
  systemctl restart httpd
  vim /www/laosiji.com/login/webtest#写一份测试文本
  Welcome log in
  打开浏览器写入login.laosiji.com



  选择Add Excetion

  选择Confirm Security Exception
  得到证书网页即可正常显示




页: [1]
查看完整版本: 运维学习笔记Apache服务