Apache
来源:互联网 发布:行政区划代码省级sql 编辑:程序博客网 时间:2024/06/05 18:30
1.配置好yum,安装httpd服务 yum install httpd -y
systemctl start httpd
systemctl enable httpd
systemctl stop firewalld
systemctl disable firewalld
2.apache的基本配置
默认发布文件 index.html
默认配置文件 /etc/httpd/conf/httpd.conf
默认发布目录 /var/www/html
默认端口 80
3.修改基本配置 vim /etc/httpd/conf/httpd.conf
(修改默认发布文件 DirectoryIndex westos.com)
(修改默认发布目录 selinux为disabled状态
DocumentRoot "/westos/www/test"
<Directory "/westos/www/test">
Require all granted
</Directory>)
(修改默认发布目录 selinux为enforcing状态
DocumentRoot "/westos/www/test"
<Directory "/westos/www/test">
Require all granted
</Directory>)
配置安全上下文 semanage fcontext -a -t httpd_sys_content'/westos(/.*)? 'restorecon -RvvF /westos/)
(查询selinux的状态 getenforce)
重启服务 systemctl restart httpd
3.新建默认发布目录 mkdir /westos/www/test -p
新建默认发布文件 vim /westos/www/test/westos.html (westos's page)
测试
5.控制访问
只允许143主机访问 vim/etc/httpd/conf/httpd.conf (<Dierctory "/var/www/html/admin">
Order Deny,Allow
Deny from ALL
Allow from 172.25.254.143
</Directory>)
测试
6.设定用户访问
设置用户admin和密码 htpasswd -cm /etc/httpd/accessuser admin
修改配置文件 vim /etc/httpd/conf/httpd.conf
(<Directory "/westos/www/test">
Require all granted
</Directory>
<Directory "/var/www/html/admin">
AuthUserFile /etc/httpd/ accesssuser 用户认证文件
AuthName "please input your name and password" 用户认证提示信息
Authtype basic 认证类型
Require vaild-user 用户认证,认证文件里的所有用户都可以访问
</Directory>
</Directory>
<Directory "/var/www/html/admin">
AuthUserFile /etc/httpd/ accesssuser
AuthName "please input your name and password"
Authtype basic
Require user admin 只允许admin用户访问
</Directory>)
测试
7.apache 的语言支持
默认支持HTML
PHP语言
安装php服务 yum install php -y
写php测试 vim /var/www/html/index.php (<?php
phpinfo()
?>)
测试
CGI语言
创建默认 发布目录 mkmdir /var/www/html/cgi
编写默认发布文件 vim index.cgi(#! /user/bin/perl
print "Content-type: text/html\n\n";
print date)
给文件可执行权限 chmod +x index.cgi
保证selinux的状态为disabled
重启服务 systemctl restart httpd
8.虚拟主机
在访问不同域名时显示不同主页
建立测试页 cd /var/www
mkdir virtual /money.westos.com/html -p
mkdir virtual /news.westos.com/html -p
echo "money.westos.com's page" > virtual /money.westos.com/html/index.html
echo "news.westos.com's page" >virtual /news.westos.com/html/index.html)
配置
未指定域名访问 vim /etc/httpd/conf.d/default.conf (<Virtualhost _default_:80 虚拟主机开启80端口
DecumentRoot "/var/www/html" 虚拟主机默认发布目录
CustomLog "logs/default.log combined 虚拟主机日志
</Virtualhost>)
指定域名访问
vim /etc/httpd/conf.d/money.conf (1) (<Virtualhost *:80>
ServerName "money.westos.com" 指定域名
DecumentRoot "/var/www/virtual/money.westos.com/html" 指定默认目录
CustomLog "logs/money.log combined 虚拟主机日志
</Virtualhost>
<Directory "/var/www/virtual/money.westos.com/html">
Require all granted
</Directory>
(2) <Virtualhost *:80>
ServerName "news.westos.com" 指定域名
DecumentRoot "/var/www/virtual/news.westos.com/html" 指定默认目录
CustomLog "logs/news.log combined 虚拟主机日志
</Virtualhost>
<Directory "/var/www/virtual/news.westos.com/html">
Require all granted
</Directory>)
配置解析 vim /etc/hosts (172.25.254.143 www.westos.com money.westos.com news.westos.com)
测试访问 www.westos.com money.westos.com news.westos.com
- Apache
- APACHE
- Apache
- Apache
- apache
- Apache
- apache
- Apache
- Apache
- Apache
- Apache
- apache
- Apache
- apache
- apache
- apache
- Apache
- Apache
- Head First 设计模式学习——装饰者模式
- 关于bootstrap 对<input type ="file">的美化
- 适配器模式的应用
- c++实验5-项目5
- C++作业6
- Apache
- Kotlin/Native Tech Preview: Kotlin without a VM
- [水文]自创-多方向文本检测自研结果
- centos 7.0 如何安装php环境 centos7安装mariadb的正确命令
- Kotlin成为Android开发首选语言——你绝对不能错过的
- 字符串匹配的KMP算法
- Web12.浏览器兼容
- 3.查准率、查全率
- 工作流引擎Activiti学习第五天(十)--- 并行网关