apache服务

1、提供apache用来提供http
yum install httpd.x86_64

2、设置防火墙及selinx
在services中添加http
firewall-cmd --permanet --add-service=http
firewall-cmd --reload

selinux为enforcing

3、默认发布目录
/var/www/html
默认发布文件
index.html

#4.apache的基础信息
#主配置目录: /etc/httpd/conf
#主配置文件: /etc/httpd/conf/httpd.conf
#子配置目录: /etc/httpd/conf.d/
#子配置文件: /etc/httpd/conf.d/*.conf
#默认发布目录: /var/www/html
#默认发布文件: index.html
#默认端口: 80
#默认安全上下文:httpd_sys_content_t
#程序开启默认用户: apache
#apache日志: /etc/httpd/logs/
*

4、修改默认设置
端口设置:
netstat -antlupe |grep httpd
查看http能够使用的端口
semange port -l |grep http

进入/etc/httpd/conf/httpd.conf
修改Listen 666

修改防火墙的端口开启
firewall-cmd --permanent --add-port=666/tcp
firewall-cmd --permanent --reload

若所设置的端口没在http可使用端口中需添加
添加http端口
semanage port -a -t http_port_t -p tcp 666

测试:
重启服务后,查看http端口
netstat -antlupe |grep httpd

修改默认发布文件:

/etc/httpd/conf/httpd.conf

/etc/httpd/conf/httpd.conf
164 DirectoryIndex index.html admin.html ##当index.html不存在时访问test.html

修改默认发布目录
120 DocumentRoot “/admin/www/html”
121 <Directory “/admin/www”>
122 Require all granted
123

semanage fcontext -a -t httpd_sys_content_t ‘/admin/www(/.*)?’
restorecon -RvvF /admin/www/

#5.apache的虚拟主机

vim /etc/httpd/conf.d/vhost.conf (vhost随意设定)

DocumentRoot "/var/www/html" CustomLog "logs/default.log" combined

<VirtualHost *:80>
ServerName host.westos.com #指定站点名称
DocumentRoot “/var/www/virt/host” #站点默认发布目录
CustomLog “logs/host.logs” combined #站点日志combined标示四种日志的集合

<Directory “/var/www/virt/host”>
Require all granted

<VirtualHost *:80>
ServerName news.westos.com
DocumentRoot “/var/www/virt/news”
CustomLog “logs/news.logs” combined

<Directory “/var/www/virt/news”>
Require all granted

建立目录并建立默认发布文件
mkdir -p /var/www/virt/host
mkdir -p /var/www/virt/news
vim index.html

设定解析
/etc/hosts
172.25.254.119 www.admin.com host.admin.com news.admin.com

6、访问设置

基于ip
配置文件:/etc/httpd/conf.d/vhost.conf
在conf.d 下任意名字以conf结尾
5 <Directory “/var/www/html/test”>
6 Order deny,allow ##列表读取顺序,后读取的列表会覆盖限度去内容的重复部分
7 Allow from 172.25.254.119
8 Deny from all
9

基于用户
htpasswd -cm /etc/httpd/userlist admin
htpasswd -m /etc/httpd/userlist student
若文件已经存在则不需要加-c,若加上则会覆盖
c create m md5加密方式

配置文件:/etc/httpd/conf.d/vhost.conf

<Directory “/var/www/virt”>
11 AuthUserFile /etc/httpd/Userlist
12 AuthName “Please input your name and password”
13 AuthType basic
14 #Require user admin
15 Require valid-user
16

输入ip进行访问

7、apache支持的语言
(1)html
(2)php
1、安装php
2、在默认发布目录下编写index.php

<?php phpinfo(); ?>

3、修改apache配置文件设置默认读取文件
/etc/httpd/conf/httpd.conf
4、重启服务并测试
172.25.254.119/index.php

(3)cgi
1、建立cgi目录
mkdir -p /var/www/html/cgi
2、修改安全上下文
semanager fcontent -a -t httpd_sys_script_exec_t ‘/var/www/html/cgi(/.*)?’
restorecon -RvvF /var/www/html/cgi/
3、编写cgi文件
vim /var/www/html/cgi/index.cgi

#!/usr/bin/perl
print “Content-type: text/html\n\n”;
print date;

4、修改cgi文件权限
chmod +x /var/www/html/cgi/index.cgi

5、修改配置文件
配置文件:/etc/httpd/conf.d/vhost.conf
在conf.d 下任意名字以conf结尾
17 <Directory “/var/www/html/cgi”>
18 Options +ExecCGI
19 AddHandler cgi-script .cgi
20

(4)wsgi
1、安装mod_wsgi
yum install mod_wsgi
2、编写wsgi文件
/var/www/html/cgi/webapp.wsgi

#!/usr/bin/env python
import time

def application (environ, start_response):
response_body = ‘UNIX EPOCH time is now: %s\n’ % time.time()
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]

3、修改配置文件
配置文件:/etc/httpd/conf.d/vhost.conf
在conf.d 下任意名字以conf结尾
<VirtualHost *:80>
ServerName wsgi.admin.com
WSGIScriptAlias /WSGI /var/www/html/cgi/webapp.wsgi

4、添加解析
/etc/hosts
172.25.254.119 wsgi.admin.com

8、https
1、安装mod_ssl和crypto-utils
mod_ssl为提供https服务
crypto-utils提供生成证书和密钥
2、生成证书和密钥
genkey www.admin.com

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值