CentOS7/RedHat7的Apache配置介绍
这里我们介绍yum安装httpd yum install -y httpd
[root@100 ~]# systemctl restart httpd
[root@100 ~]# systemctl enable httpd
ln -s '/usr/lib/systemd/system/httpd.service' '/etc/systemd/system/multi-user.target.wants/httpd.service'
[root@100 ~]# vim /etc/httpd/
安装的版本介绍
备份一下配置文件
[root@100 ~]# cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.bak
需要了解的知识块
1、了解Apache的基本配置
2、配置动态页面:CGI、wsgi、ssl
3、配置一个虚拟主机
4、配置https
1、了解Apache的基本配置
编辑Apache的配置文件httpd.conf 路径在/etc/httpd/conf/httpd.conf
默认的配置文件路径ServerRoot "/etc/httpd"
默认监听的端口Listen 80
模块存放路径[root@100 ~]# ls /etc/httpd/conf.modules.d/
所属者和所属组
User apache
Group apache
默认安装的时候他会创建一个不可登录系统的用户
apache❌48:48:Apache:/usr/share/httpd:/sbin/nologin
默认的管理员邮箱是ServerAdmin root@localhost
站点配置#ServerName www.example.com:80 默认是禁用的
站点的目录设置
<Directory "/var/www"> ------------<Directory "/var/www/html">
AllowOverride None ------------------Options Indexes FollowSymLinks
# Allow open access: -----------------AllowOverride None
Require all granted --------------------Require all granted
----------------------------
站点设置项:
(Options 里的indexes是开启开启索引,FollowSymLinks是允许链接文件--需要修改上下文chcon -R --reference=/var/www/html /new)
(AllowOverride None 是否允许单前目录下的一个隐藏文件.htaccess里的配置覆盖当前httpd.conf
的里设置--用于http的认证
在网页的根目录下创建一个
[root@100 html]# cat /var/www/html/.htaccess
AuthType Basic
AuthName haha
AuthUserfile /etc/httpd/conf/.htpasswd
Require user tom
/etc/httpd/conf/.htpasswd这个文件需要用
[root@100 html]# htpasswd -cm /etc/httpd/conf/.htpasswd tom ##-cm 创建用MD5
加密
New password:
Re-type new password:
Adding password for user tom
[root@100 html]#
修改后的AllowOverride AuthConfig 接下来访问就要提示用户密码
)
(Require all granted 允许所有
Require all denied 拒绝所有
Require ip 192.168.1.1 允许这地址访问
Require ip 192.168.1.0/24 这个端地址可以访问
Require local
Require ip 192.168.1.1 192.168.2.2 这俩个地址可以访问
)
站点的文档目录DocumentRoot "/var/www/html"
设置文件的权限
<Files ".ht*">
Require all denied
错误日志ErrorLog "logs/error_log"
Alias 设置别名 # Alias /webpath /full/filesystem/path默认是禁用的--每设置一个目录就需要加一个
<Directory "/mnt/html">
AllowOverride None
# Allow open access:
Require all granted
2、配置动态页面:CGI、wsgi、ssl
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/" 这是CGI的脚本路径
[root@100 cgi-bin]# pwd
/var/www/cgi-bin
[root@100 cgi-bin]# cat *
#!/usr/bin/perl
print "Content-Type: text/html; charset=UTF-8\n\n";
$time=localtime();
print "$time\n"
#!/bin/bash
echo "Content-Type: text/html; charset=UTF-8"
echo
date +'%F %T'
hostname
[root@100 cgi-bin]#
浏览器访问http://xxxxxxxxx/cgi-bin/aa.sh 实现的效果就是获取本地时间
wsgi是python实现的一种动态页面功能默认没有按照
[root@100 cgi-bin]# yum install -y mod_wsgi
在/etc/httpd/conf/httpd.conf配置文件里修改
253 ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
254
255
256
257 WSGIScriptAlias /wsgi-bin/ "/var/www/cgi-bin/"
浏览器访问测试http://xxxxxx/wsgi-bin/aa.wsgi 实现的效果就是显示本地时间
[root@100 wsgi-bin]# cat aa.wsgi
#!/usr/bin/env python
import time
def application (environ, start_response):
a = time.ctime(time.time())
response_body = 'This Dynamic WSGI Page Was Generated at: \n%s\n'%a
status = '200 OK'
response_headers = [('Content-Type', 'text/plain'),
('Content-Length', '1'),
('Content-Length',str(len(response_body)))]
start_response(status, response_headers)
return [response_body]
SSI 设置动态页面是需要在配置文件里设置
在站点目录这里添加includes
Options Indexes FollowSymLinks Includes ##include包含
ssi设置的页面默认是*.shtml
Vim /var/www/html/index.shtml
helloworld
当前的用户是: <!--#exec cmd="whoami" -->
当前的时间是:<!--#echo var="DATE_LOCAL" -->
访问者的ip是:<!--#echo var="REMOTE_ADDR"-->
~
测试连接http://xxxxx/index.shtml
[an error occurred while processing the directive] ##调用刚才的cgi脚本
注意点:
站点根目录下的默认是访问index.html怎么把它设置成index.shtml呢?
就需要用到地址重写功能
在http的配置文件里追加
362 RewriteEngine on
363 RewriteRule ^/?$ /index.shtml [R]
他会使你的浏览器默认重定向站点的shtml里
3、虚拟主机的配置
默认http的配置文件在这里
# Load config files in the "/etc/httpd/conf.d" directory, if any.
IncludeOptional conf.d/*.conf
这里我们写一个基于一个IP解析俩个不同站点的案例(基于主机名的虚拟主机)
这里复制一个模板文件
[root@100 ~]# cp /usr/share/doc/httpd-2.4.6/httpd-vhosts.conf /etc/httpd/conf.d/vhosts.conf
[root@100 conf.d]# echo zzz > /var/www/html/index.html;echo cc /cc/index.html
[root@100 conf.d]# systemctl restart httpd
[root@100 conf.d]# cat vhosts.conf
<VirtualHost *:80>
DocumentRoot /cc
ServerName www.cc.com
ErrorLog "/var/log/httpd/www.cc.com-error_log"
CustomLog "/var/log/httpd/dummy-www.cc.com.com-access_log" common
</VirtualHost>
<Directory "/cc">
AllowOverride None
# Allow open access:
Require all granted
</Directory>
<VirtualHost *:80>
DocumentRoot /var/www/html
ServerName www.zzz.com
ErrorLog "/var/log/httpd/www.zzz.com-error_log"
CustomLog "/var/log/httpd/dummy-www.zzz.com.com-access_log" common
</VirtualHost>
<Directory "/var/www/html">
AllowOverride None
# Allow open access:
Require all granted
</Directory>
cho
[root@100 conf.d]# chcon -R --reference=/var/www/html /cc #更改上下文
(如果是基于ip的虚拟主机只需修改你的dns解析即可)
基于端口的虚拟主机
[root@100 conf.d]# cat vhosts.conf
<VirtualHost *:801>
DocumentRoot /cc
ServerName www.cc.com
ErrorLog "/var/log/httpd/www.cc.com-error_log"
CustomLog "/var/log/httpd/dummy-www.cc.com.com-access_log" common
</VirtualHost>
<Directory "/cc">
AllowOverride None
# Allow open access:
Require all granted
</Directory>
<VirtualHost *:802>
DocumentRoot /var/www/html
ServerName www.zzz.com
ErrorLog "/var/log/httpd/www.zzz.com-error_log"
CustomLog "/var/log/httpd/dummy-www.zzz.com.com-access_log" common
</VirtualHost>
<Directory "/var/www/html">
AllowOverride None
# Allow open access:
Require all granted
</Directory>
[root@100 conf.d]# cat /etc/httpd/conf/httpd.conf
#Listen 12.34.56.78:80
Listen 80
Listen 801
Listen 802
简书链接
有探讨的在下方留言
--END--
CentOS7/RedHat7的Apache配置介绍的更多相关文章
- centos7防火墙的简单配置介绍
centos7版本 1.查看已开放的端口(默认不开放任何端口) firewall-cmd --list-ports 2.开启80端口 firewall-cmd --zone=public(作用域) - ...
- SVN CentOS7 下配置svn的安装及基础配置介绍
CentOS7 下配置svn的安装及基础配置介绍 by:授客 QQ:1033553122 目录 一. 二. 三. 四. 五. 六. 七. 一. 实践环境 CentOS 7操作系统(CentO ...
- CentOS7服务器中apache、php7以及mysql5.7的安装配置代码
CentOS7服务器中apache.php7以及mysql5.7的配置代码如下所示: yum upgradeyum install net-tools 安装apache (http://m.86822 ...
- LINUX服务器搭建和常用配置介绍
服务器搭建 : 搭建私有CA服务器 : http://www.cnblogs.com/zhaojiedi1992/p/zhaojiedi_linux_011_ca.html搭建samba服务器 : h ...
- Tomcat:利用Apache配置反向代理、负载均衡
本篇主要介绍apache配置反向代理,介绍了两种情况:第一种是,只使用apache配置反向代理:第二种是,apache与应用服务器(tomcat)结合,配置反向代理,同时了配置了负载均衡. 准备工作 ...
- apache 配置详解
三种MPM介绍 Apache 2.X 支持 ...
- centos7中安装、配置、验证、卸载redis
本文介绍在centos7中安装.配置.验证.卸载redis等操作,以及在使用redis中的一些注意事项. 一 安装redis 1 创建redis的安装目录 利用以下命令,切换到/usr/local路径 ...
- Centos 7 磁盘阵列配置介绍(RAID)
转自:https://blog.51cto.com/gaowenlong/2086918 Centos 7 磁盘阵列配置介绍每当我们提到磁盘阵列,相信广大管理员并不陌生,比如我们一般安装服务器系统的时 ...
- apache配置,apache直接打开文件而不下载问题
apache什么用,如何下载的上面就不说了,apache的配置是一个非常复杂的工作,下面介绍最基本的apache配置吧,再介绍配置文件管理系统. 安装过后需修改配置: 修改httpd.conf配置文件 ...
随机推荐
- Unix发展史
简述 了解过去,我们才能知其然,更知所以然.总结过去,我们才会知道明天该何去何从.在时间的滚轮中,许许多多的东西就像流星一样一闪而逝,而有些东西却能经受着时间的考验散发着经久的魅力,让人津津乐道.流传 ...
- @SpringBootApplication cannot be resolved to a type In STS
@SpringBootApplication cannot be resolved to a type In STS 学习了:https://stackoverflow.com/questions/4 ...
- 数据结构之---C语言实现拓扑排序AOV图
//有向图的拓扑排序 //杨鑫 #include <stdio.h> #include <stdlib.h> #include <string.h> #define ...
- Hibernate是怎么工作的——Hibernate的工作流程
举个简单的样例说明: 1.Base.java package cn.flymouse.hibernate; import java.util.Date; import org.hibernate.Qu ...
- poj_1974,最长回文字串manacher
时间复杂度为O(n),参考:http://bbs.dlut.edu.cn/bbstcon.php?board=Competition&gid=23474 #include<iostrea ...
- hdoj--2516--取石子游戏(博弈)
取石子游戏 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Subm ...
- 熟悉了下HTTP协议
HTML是一种用来定义网页的文本,会HTML,就可以编写网页: HTTP是在网络上传输HTML的协议,用于浏览器和服务器的通信.200表示一个成功的响应,后面的OK是说明.失败的响应有404 Not ...
- django 笔记6 Ajax
感谢alex~ .Django请求生命周期 输入url 进入 urls(路由系统) 指向 views(视图函数)->(获取模板) 里面的函数 再由函数返回字符串给用户 .路由系统 /index/ ...
- HTML5,CSS3新特性,与旧版的区别
HTML5新特性 (1)语意化更好的内容元素,比如 article.footer.header.nav.section (2)本地存储.sessionStorage.localStorage和inde ...
- CSS3动画闪跳
Alloy Team首页的元素Hover效果 效果预览 <!DOCTYPE html> <html lang="en"> <head> < ...