博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Apache的管理和web优化
阅读量:3962 次
发布时间:2019-05-24

本文共 5508 字,大约阅读时间需要 18 分钟。

Apache的管理和web优化

1.Apache的作用

在web被访问时通常使用http://的方式

http:// ##超文本传输协议
http:// 超文本传输协议提供软件:
Apache
nginx
stgw
jfe
Tengine

2.Apache的安装

dnf install httpd.x86_64 -y

3.Apache的启用

systemctl enable --now httpd			##开启服务并设定服务位开机启动firewall-cmd --list-all			##查看火墙信息firewall-cmd --permanent --add-service=http	##在火墙中永久开启http访问firewall-cmd --permanent --add-service=https	##在火墙中永久开启https访问firewall-cmd --reload				##刷新火墙使设定生效

4.Apache的基本信息

服务名称: httpd

配置文件:
/etc/httpd/conf/httpd.conf ##主配置文件
/etc/httpd/conf.d/*.conf ##子配置文件
默认发布目录: /var/www/html
默认发布文件: index.html
默认端口: 80 #http 443 #https
用户: apache
日志: /etc/httpd/logs

5.Apache的基本配置

1.Apache端口修改

[root@d ~]# vim /etc/httpd/conf/httpd.conf45 #Listen 8046 Listen 8080[root@d ~]# firewall-cmd --permanent --add-port=8080/tcp[root@d ~]# firewall-cmd --reload[root@d ~]# systemctl restart httpd[root@d ~]# ss -antlupe | grep 8080# 在网页内输入ip后发现网页报错,但在ip:8080就可以正常显示,apache的ip默认端口为80。

2.默认发布文件

[root@d html]# vim /etc/httpd/conf/httpd.confDirectoryIndex test.html index.html[root@d html]# vim test.html[root@d html]# systemctl restart httpd

3.默认发布目录

[root@d www]# mkdir westos[root@d www]# vim /etc/httpd/conf/httpd.conf 123 #DocumentRoot "/var/www/html"124 DocumentRoot "/var/www/westos"125 
126 Require all granted127
[root@d westos]# vim index.html[root@d westos]# systemctl restart httpd

6.Apache的访问控制

1.基于客户端ip的访问控制

[root@d westos]# vim /etc/httpd/conf/httpd.conf 125 
126 Order Deny,Allow127 Allow from 真机ip128 Deny from all129
# 只允许自己的真机访问发布目录里的内容,否定其他用户[root@d westos]# systemctl restart httpd[root@d westos]# vim /etc/httpd/conf/httpd.conf 125
126 Order Allow,Deny127 Allow from all128 Deny from 真机ip129
# 只允许其他用户访问,自己真机访问被拒绝[root@d westos]# systemctl restart httpd

2.基于用户认证

vim /etc/httpd/conf/httpd.conf
AuthUserfile /etc/httpd/htpasswdfile ##指定认证文件 AuthName "Please input your name and password" ##认证提示语 AuthType basic ##认证类型 Require user admin ##允许通过的认证用户 2选1 Require valid-user ##允许所有用户通过认证 2选1
htpasswd -cm /etc/httpd/htpasswdfile admin ##生成认证文件注意:当/etc/httpd/htpasswdfile存在那么在添加用户时不要加-c参数否则会覆盖源文件内容

7.Apache的虚拟主机

[root@d html]# echo default > index.html[root@d www]# mkdir -p web.com/{a,b}[root@d a]# vim index.htmla.page[root@d b]# vim index.htmlb.page[root@d conf.d]# vim web.conf   1 
2 DocumentRoot "/var/www/html" 3 CustomLog logs/default.log combined 4
5 6
7 ServerName a.web.com 8 DocumentRoot "/var/www/web.com/a" 9 CustomLog logs/a.log combined 10
11 12
13 ServerName b.web.com 14 DocumentRoot "/var/www/web.com/b" 15 CustomLog logs/b.log combined 16
[root@d conf.d]# systemctl restart httpd在浏览器所在主机中vim /etc/hosts虚拟机ip-100 www.web.com a.web.ocm b.web.com# 通过输入域名可以解析到ip查看到发布的内容

8.Apache的语言支持

dnf install httpd-manual -y 安装后可以查看apache的一些文件。

#php#

dnf install php -y[root@d html]# vim index.php
[root@d html]# systemctl restart httpd

#cgi# perl

[root@d html]# mkdir cgidir[root@d cgidir]# vim index.cgi#!/usr/bin/perlprint "Content-type: text/html\n\n";print `date`;[root@d cgidir]# chmod +x index.cgi[root@d cgidir]# vim /etc/httpd/conf.d/web.conf 
Options +ExecCGI AddHandler cgi-script .cgi
[root@d cgidir]# systemctl restart httpdfirefox http://ip/cgidir/index.cgi

#wsgi# python

[root@d cgidir]# dnf install python3-mod_wsgi.x86_64 -y[root@d html]# mkdir wsgidir[root@d html]# vim /etc/httpd/conf.d/web.conf 23 
24 ServerName wsgi.web.com 25 WSGIScriptAlias / /var/www/html/wsgidir/index.wsgi 26
[root@d wsgidir]# vim index.wsgi 1 def application(env, westos): 2 westos( '200 ok', [('Content-Type', 'text/html')]) 3 return [b'hello wsgi!'][root@d wsgidir]# chmod +x index.wsgi [root@d wsgidir]# systemctl restart httpd

9.Apache的加密访问

##安装加密插件 http变为https的加密网址[root@d wsgidir]# dnf install mod_ssl -y[root@d httpd]# openssl genrsa -out www.web.com.key 2048 #生成私钥[root@d httpd]# openssl req -new -key www.web.com.key -out www.web.com.csr##生成证书签名文件[root@d httpd]# openssl x509 -req -days 365 -in www.web.com.csr -signkey www.web.com.key -out www.web.com.crt#生成证书x509 证书格式-req 请求-in 加载签证名称-signkey[root@d login]# vim /etc/httpd/conf.d/web.conf  28 
29 ServerName login.web.com 30 RewriteEngine on 31 RewriteRule ^(/.*)$ https://%{
HTTP_HOST}$1 32
33 34
35 ServerName login.web.com 36 DocumentRoot /var/www/web.com/login 37 CustomLog logs/login.log combined 38 SSLEngine on 39 SSLCertificateFile /etc/httpd/www.web.com.crt 40 SSLCertificateKeyFile /etc/httpd/www.web.com.key 41
[root@d web.com]# mkdir login[root@d login]# vim index.html[root@songtao westos]# vim /etc/hosts[root@d login]# firewall-cmd --list-all[root@d login]# systemctl restart httpd

10.Squid+Apache

linux的虚拟机上网

1.在虚拟机里的[root@d ~]# vim /etc/resolv.conf 添加真机能上网的解析地址nameserver ip。

2.[root@d ~]# vim /etc/sysconfig/network在这个文件里添加全局网关,网关为能上网主机的ip。或者添加临时网关ip route add default via ip。

squid 正向代理

在能上网的主机里操作dnf install squid -yvim /etc/squid/squid.conf59 http_access allow all65 cache_dir ufs /var/spool/squid 100 16 256systemctl restart squid firewall-cmd --permanent --add-port=3128/tcpfirewall-cmd --reload

在虚拟机里进行测试

squid反向代理

把自己机子的apache去除[root@d squid]# dnf remove httpd[root@d squid]# vim /etc/squid/squid.conf 62 http_port 80 vhost vport 63 cache_peer 172.25.254.113 parent 80 0 proxy-only  ##有apache的主机113[root@d squid]# systemctl restart squid

测试:

firefox 被删除apache的ip
访问看到的时172.25.254.113上的数据。

转载地址:http://wnhzi.baihongyu.com/

你可能感兴趣的文章
Mule ESB-Content-Based Routing Tutorial(2)
查看>>
Mule ESB-Content-Based Routing Tutorial(3)
查看>>
年末项目经验总结
查看>>
做事情要放下面子,拿起责任
查看>>
敏捷开发实践(1)-故事工作量估算导致的问题
查看>>
记一次解决jenkins持续构建,自动部署的问题
查看>>
敏捷开发实践(2)-要不要文档?
查看>>
《java系统性能调优》--2.缓存
查看>>
JAVA注解引发的思考
查看>>
写博意味着什么
查看>>
比较Cint() , int() , fix() ,round()的区别
查看>>
举例说明常用字符串处理函数
查看>>
软件生存期模型
查看>>
制定计划(问题的定义,可行性研究)
查看>>
需求分析
查看>>
软件设计
查看>>
程序编码
查看>>
软件测试
查看>>
软件维护
查看>>
软件项目管理
查看>>