apache 服务
来源:互联网 发布:数据库查询去除重复 编辑:程序博客网 时间:2024/05/17 20:12
yum install httpd -y
systemctl start httpd
systemctl stop firewalld
systemctl enable httpd
systemctl disable firewalld
1.apache的默认发布文件
index.html
2.apache的配置文件
/etc/httpd/conf/httpd.conf
/etc/httpd/conf.d/*.conf
3.apache的默认发布目录
/var/www/html
4.apache的默认端口
80
apache的基本配置
1.修改默认发布文件
vim /etc/httpd/conf/httpd.conf
172 DirectoryIndex index.html
systemctl restart httpd
2.修改默认发布目录
##当selinux是disable状态vim /etc/httpd/conf/httpd.conf
120 DocumentRoot "/westos/html"
<Directory "/westos/html">
Require all granted
</Directory>
systemctl restart httpd
当selinux是enforcing状态
vim /etc/httpd/conf/httpd.conf
120 DocumentRoot "/westos/www/test"
<Directory "/westos/www/test">
Require all granted
</Directory>
systemctl restart httpd
semanage fcontext -a -t httpd_sys_content_t '/westos(/.*)?'
restorecon -RvvF /westos
3.apache的访问控制
设定ip的访问
vim /etc/httpd/conf/httpd.conf
<Directory "/var/www/html/admin"> 允许所有人访问admin目录但是拒绝100主机
Order Allow,Deny
Allow from All
Deny from 192.268.122.100
</Directory>
<Directory "/var/www/html/admin"> 只允许250主机访问admin目录
Order Deny,Allow
Allow from 172.25.254.250
Deny from All
</Directory>
设定用户的访问
先cd进入/etc/httpd/conf 目录
执行 htpasswd -cm /etc/httpd/authfile admin1
vim /etc/httpd/conf/httpd.conf
htpasswd -m /etc/httpd/accessuser admin
vim /etc/httpd/conf/httpd.conf
<Directory "/var/www/html/admin">
AuthUserFile /etc/httpd/accessuser ##用户认证文件
AuthName "Please input your name and password !!" ##用户认证提示信息
AuthType basic 认证类型
Require valid-user 认证用户,认证文件中所有用户都可以通过
[Require user admin] 只允许认证文件中admin用户访问,二写一
</Directory>
测试
4.apache语言支持
php html cgi
html语言默认支持
php语言
1. 安装php yum install php -y
2. 在默认发布目录下创建index.php touch /var/www/html/index.php
vim index.php
phpinfo();
?>
3.在主配置文件中修改默认发布文件顺序
systemctl restart httpd
测试:
cgi语言
mkdir /var/www/html/cgi
vim index.cgi
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print `date`;
vim /etc/httpd/conf/httpd.conf
<Directory "/var/www/html/cgi">
Options +ExecCGI
AddHandler cgi-script .cgi
</Directory>
systemctl restart httpd
apache的虚拟主机
1.定义
可以让我们的一台apache服务器在被访问不同域名的时候显示
不同的主页
2.建立测试页
mkdir /westos/html/news.westos.com -p
mkdir /westos/html/gongyi.westos.com -p
echo "news's page" >/westos/html/news.westos.com/index.html
echo "gongyi's page" >/westos/html/gongyi.westos.com/index.html
3.配置
vim /etc/httpd/conf.d/default.conf 位指定域名的访问都访问default
<Virtualhost _default_:80> 虚拟主机开启的端口
DocumentRoot "/var/www/html" 虚拟主机的默认发布目录
CustomLog "logs/default.log" combined 虚拟主机日志
</Virtualhost>
vim /etc/httpd/conf.d/news.conf 指定域名news.westos.com的访问到指定默认发布目录中
vim /etc/httpd/conf.d/gongyi.conf 指定域名gongyi.westos.com的访问到指定默认发布目录中
在浏览器所在主机中
vim /etc/hosts
172.25.254.100 www.westos.com news.westos.com gongui.westos.com
访问 www.westos.com
访问news.westos.com
访问gongui.westos.com
网页加密访问https
1.https定义
Hyper text transfer protocol over Secure socker layer
通过ssl
2.配置
yum install mod_ssl -y
yum install crypto-utils -y
genkey www.westos.com
/etc/pki/tls/private/www.westos.com.key
/etc/pki/tls/certs/www.westos.com.crt
vim /etc/httpd/conf.d/login.conf
<Virtualhost *:443>
ServerName "login.westos.com"
DocumentRoot "/var/www/virtual/login.westos.com/html"
CustomLog "logs/login.log" combined
SSLEngine on ##开始https功能
SSLCertificateFile /etc/pki/tls/certs/www.westos.com.crt #证书
SSLCertificateKeyFile /etc/pki/tls/private/www.westos.com.key ##密钥
</Virtualhost>
<Directory "/var/www/virtual/login.westos.com/html">
Require all granted
</Directory>
<Virtualhost *:80> ##网页重写实现自动访问https
ServerName login.westos.com
RewriteEngine on
RewriteRule ^(/.*)$ https://%{HTTP_HOST}$1 [redirect=301]
</Virtualhost>
##########################################################################
## ##
## ^(/.*)$ https://%{HTTP_HOST}$1 [redirect=301] ##
## ##
## ^(/.*)$ 客户主机在地址栏中写入的所有字符,不包含换行符 ##
## https:// 定向成为的访问协议 ##
## %{HTTP_HOST} 客户请求主机 ##
## $1 $1的值就表示^(/.*)$的值 ##
## [redirect=301] 临时重定向 302永久重定向 ##
## ##
##########################################################################
mkdir /var/www/virtual/login.westos.com/html -p
vim /var/www/virtual/login.westos.com/html/index.html
systemctl restart httpd
测试:
在客户主机中添加解析
vim /etc/hosts
172.25.254.100 login.westos.com
访问http://login.westos.com 会自动跳转到
https://login.westos.com 实现网页数据加密传输
- Apache服务
- apache 服务
- apache服务
- apache服务
- DHCP和Apache服务
- 安装apache服务
- Apache添加NT服务
- apache 目录服务 配置
- apache服务崩溃捉虫记
- Apache服务 for Windows
- Centos 配置Apache服务
- 配置虚拟机Apache服务
- 配置http服务 Apache
- Apache配置服务
- Apache WebDav服务
- Apache 服务启动不了
- Apache服务启动
- apache服务管理
- 虚拟机性能检测和故障处理工具
- C++打印图片的方法
- 利用unity + visual studio 自制一款小游戏
- String s=new String("xyz")及String s="a"+"b"+"c"+"d";创建几个String对象的问题
- 欢迎使用CSDN-markdown编辑器
- apache 服务
- Dijkstra算法 Atcoder-070-D
- 什么情况下会用到try-catch
- Android异步消息处理机制
- CF Round #428( Div.2)BCDE
- 基于大神张林峰指导 自编 Git 开发流程2.0
- mysql开启慢查询
- Ext JS 类系统简介
- ES6多重箭头函数