本文共 5508 字,大约阅读时间需要 18 分钟。
在web被访问时通常使用http://的方式
http:// ##超文本传输协议 http:// 超文本传输协议提供软件: Apache nginx stgw jfe Tenginednf install httpd.x86_64 -y
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 ##刷新火墙使设定生效
服务名称: httpd
配置文件: /etc/httpd/conf/httpd.conf ##主配置文件 /etc/httpd/conf.d/*.conf ##子配置文件 默认发布目录: /var/www/html 默认发布文件: index.html 默认端口: 80 #http 443 #https 用户: apache 日志: /etc/httpd/logs[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。
[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
[root@d www]# mkdir westos[root@d www]# vim /etc/httpd/conf/httpd.conf 123 #DocumentRoot "/var/www/html"124 DocumentRoot "/var/www/westos"125126 Require all granted127 [root@d westos]# vim index.html[root@d westos]# systemctl restart httpd
[root@d westos]# vim /etc/httpd/conf/httpd.conf 125126 Order Deny,Allow127 Allow from 真机ip128 Deny from all129 # 只允许自己的真机访问发布目录里的内容,否定其他用户[root@d westos]# systemctl restart httpd[root@d westos]# vim /etc/httpd/conf/httpd.conf 125126 Order Allow,Deny127 Allow from all128 Deny from 真机ip129 # 只允许其他用户访问,自己真机访问被拒绝[root@d westos]# systemctl restart httpd
vim /etc/httpd/conf/httpd.confAuthUserfile /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参数否则会覆盖源文件内容
[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 12 DocumentRoot "/var/www/html" 3 CustomLog logs/default.log combined 4 5 67 ServerName a.web.com 8 DocumentRoot "/var/www/web.com/a" 9 CustomLog logs/a.log combined 10 11 1213 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查看到发布的内容
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.confOptions +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 2324 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
##安装加密插件 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 2829 ServerName login.web.com 30 RewriteEngine on 31 RewriteRule ^(/.*)$ https://%{ HTTP_HOST}$1 32 33 3435 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
1.在虚拟机里的[root@d ~]# vim /etc/resolv.conf 添加真机能上网的解析地址nameserver ip。
2.[root@d ~]# vim /etc/sysconfig/network在这个文件里添加全局网关,网关为能上网主机的ip。或者添加临时网关ip route add default via ip。在能上网的主机里操作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
在虚拟机里进行测试
把自己机子的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/