萌新的linux之旅23

Apache 简介
Apache HTTP Server(简称Apache)是Apache软件基金会的一个开放源码的 页服务器,可以在大多数计算机操作系统中运行,由于其多平台和安全性被广泛使用,是最流行的Web服务器端软件之一。它快速、可靠并且可通过简单的API扩展,将Perl/Python等解释器编译到服务器中。[2]
Apache HTTP服务器是一个模块化的服务器,源于NCSAhttpd服务器,经过多次修改,成为世界使用排名第一的Web服务器软件。
它可以运行在几乎所有广泛使用的计算机平台上。
Apache
安装
yum install -y httpd
systemctl start httpd
systemctl enable httpd
/var/www/html 默认发布目录
/var/www/html/index.html 默认发布文件

更改默认发布文件
vim /etc/httpd/conf/httpd.conf apache主配置文件
164 DirectoryIndex index.html ===> DirectoryIndex westos
systemctl restart httpd 重启服务

测试,用浏览器打开

设置登陆密码
vim /etc/httpd/conf/httpd.conf
120 DocumentRoot “/haha/html”
121
122# Require all granted 授权所有人
123 AuthUserFile /etc/httpd/conf/authfile 指定文件
124 AuthName “please input your name and password.3q”
125 AuthType basic
126# Require user haha 指定用户
127 Require valid-user 指定文件中的用户
128

不输入密码则登陆不了

cd /etc/httpd/conf.d/
vim default.conf
default:80 > 80 ,apache 服务默认打开的端口
DocumentRoot “/var/www/html”
CustomLog “logs/default.log” combined

vim news.conf

ServerName news.haha.com
DocumentRoot /var/www/haha/news.haha.com
CustomLog “logs/news.log” combined


Require all granted

vim game.conf

ServerName game.haha.com
DocumentRoot /var/www/haha/game.haha.com
CustomLog “logs/game.log” combined


Require all granted

genkey www.westos.com 去给www.westos.com生成证书
512 最短的
1024是最快
2048标准
需要敲键盘和移动鼠标,生成密钥,2048花费时间太长,所以选择1024

发给CA认证机构是要收取认证费用的,所以在实验环境,可以选择不发,对环境没有影响
Protecting your private key
不要去填,直接next
后面要自己写,不然每次进入阿帕奇都要输入密码

输入国家,省会,城市,公司,名称, 址
NEXT之后就完成了
出现一些信息提示,发现有钥匙和证书的存放地方
还会在/etc/httpd/conf.d下生成ssl.conf,这里面的文件就是默认443端口的配置
按照提示中的地址,修改ssl.conf中的所示部分

将初始端口变成443
新建虚拟主机端口80,将80中的引导到443端口
RewriteEngine on 重写功能开启
RewriteRule ^(/.*) https://访 https://访1 匹配后面的内容
[redirect=301]
301 临时重定向,访问一次,定向一次,因为 页后台会有刷新,所以一般用301
302 永久重定向

php编写 页
yum install php -y 安装php软件
在/var/www/html下编写index.php
进入/etc/httpd/conf/httpd.conf
171
172 DirectoryIndex index.php index.html westos
173
优先访问index.php ,重启apache,打开 页,你会发现已经变成php的页面

如果还是显示不出来,查看一下安全上下文,查看安全上下文是否配对,如果不配对,那就不能显示出来
semanage fcontext -l | grep cgi
/var/www/cgi-bin(/.*)all files system_u:object_r:httpd_sys_script_exec_t:s0
而ls -Zd /var/www/html/cgi
安全上下文是unconfined_u:object_r:httpd_sys_content_t:s0
所以更改
先更改selinux模式
setenforcing 0 警告
修改:
semanage fcontext -a -t httpd_sys_script_exec_t ‘/var/www/html/cgi(/.*)
restorecon -RvvF /var/www/html/cgi
setenforcing 1 变回强制模式
也可以直接关掉 selinux
再次进入地址172.25.254.109/cgi/index.cgi

文章知识点与官方知识档案匹配,可进一步学习相关知识CS入门技能树Linux入门初识Linux24694 人正在系统学习中

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2017年7月17日
下一篇 2017年7月17日

相关推荐