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配置文件 ...
随机推荐
- Linux的中断和系统调用 & esp、eip等寄存器
http://www.linuxidc.com/Linux/2012-11/74486.htm 一共三篇 中断一般分为三类: 1.由计算机硬件异常或故障引起的中断,称为内部异常中断: 2.由程序中执行 ...
- hadoop-03-安装java
hadoop-03-安装java 1,su root 2, rpm -qa|grep jdk #查看已经安装的jdk 3,rpm -e --nodeps `rpm -qa|grep jdk ` #删除 ...
- Windows server 2008 布署FTP服务器实例(适用于阿里云)!
Windows server 2008 布署FTP服务器实例(适用于阿里云). 1.打开管理.配置-用户-新建用户,如:ftp_user,并设置password.选择永只是期和password不能更改 ...
- Logical Operators (Transact-SQL)
https://docs.microsoft.com/en-us/sql/t-sql/language-elements/logical-operators-transact-sql Logical ...
- Hive框架基础(二)
* Hive框架基础(二) 我们继续讨论hive框架 * Hive的外部表与内部表 内部表:hive默认创建的是内部表 例如: create table table001 (name string , ...
- java中"".equals(A)与A.equals("")一样不?
不一样如果a为nulla = null;a.equals("")出错nullPointerException如果写为"".equals(a)-->就可以防 ...
- fill,fill-n,memset的区别
这里在网上搜集归纳了一个总结 memset函数 按照字节填充某字符 在头文件<string.h>中 因为memset函数按照字节填充,所以一般memset只能用来填充char型数组,(因为 ...
- 如何使 nginx 支撑更高并发
/** * * * * 如何使 nginx 支撑更高的并发? * 原理: * 服务器方面可以从两个方面阐述: * 1.socket 链接方面:因为每次请求都是一次连接,而 nginx 服务器配置方面默 ...
- 洛谷1726 上白泽慧音 tarjan模板
题目描述 在幻想乡,上白泽慧音是以知识渊博闻名的老师.春雪异变导致人间之里的很多道路都被大雪堵塞,使有的学生不能顺利地到达慧音所在的村庄.因此慧音决定换一个能够聚集最多人数的村庄作为新的教学地点.人间 ...
- nginx配置aliyun https
server { listen 443; server_name www.goforit.com goforit.com; ssl on; ssl_certificate cert/goforit.p ...