题目要求:在 server0 上实现动态 web 内容
- l 动态内容由名为 webapp0.example.com 的虚拟主机提供
- l 虚拟主机侦听端口为 8909
- l 从 http://classroom.example.com/content/webapp.wsgi 下载一个脚本,然后放在适当的位置,不要修改文件内容
- l 客户端访问 http://webapp0.example.com:8909 时,应该接收到动态生成的 web 页面
- l 此 http://webapp0.example.com:8909 必须能被 example.com 内所有的系统访问
知识点小贴士:
重要配置选项:
ServerRoot 服务器运行的根目录
MaxClients 能同时访问服务器的客户机数量
DocumentRoot 服务器共享文件的起始位置
listen 服务器监听的端口
ServerAdmin 管理员的信箱
User&Group 服务器运行者的身份
ErrorLog 出错日志文件
DirectoryIndex 默认文件夹索引文件
AddDefaultCharset 默认返回页面的编码
Alias 为目录设置访问别名
解题步骤:
(1)准备目录和文件:
<code>[root@server0 ~]# mkdir /var/www/webapp/<code>
<code>[root@server0 ~]# wget -O /var/www/webapp/webinfo.wsgi http://classroom.example.com/content/webapp.wsgi
--2020-03-26 09:18:04-- http://classroom.example.com/content/webapp.wsgi
Resolving classroom.example.com (classroom.example.com)... 172.25.254.254
Connecting to classroom.example.com (classroom.example.com)|172.25.254.254|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 396
Saving to: ‘/var/www/webapp/webinfo.wsgi’
100%[=====================>] 396 --.-K/s in 0s
2020-03-26 09:18:04 (45.5 MB/s) - ‘/var/www/webapp/webinfo.wsgi’ saved [396/396]
[root@server0 ~]# semanage port -a -t http_port_t -p tcp 8909/<code>
(2)防火墙放行8909端口
<code>[root@server0 ~]# firewall-cmd --add-port=8909/tcp
success
[root@server0 ~]# firewall-cmd --add-port=8909/tcp --permanent
success/<code>
(3)在/etc/httpd/conf.d中添加一个文件:webapp.conf
<code>[root@server0 ~]# vim /etc/httpd/conf.d/webapp.conf/<code>
注释:添加内容如下
<code>Listen 8909
<virtualhost>
ServerName webapp0.exmaple.com
WSGIScriptAlias / /var/www/webapp/webinfo.wsgi
/<virtualhost>/<code>
(4)重启httpd服务
<code>[root@server0 ~]# systemctl restart httpd/<code>
(5)验证:
<code>[root@server0 ~]# vim /etc/httpd/conf.d/webapp.conf
[root@server0 ~]# curl http://webapp0.example.com:8909
UNIX EPOCH time is now: 1585186407.08
[root@server0 ~]# firefox http://webapp0.example.com:8909/<code>
在Desktop0上验证:
<code>[root@desktop0 ~]# curl http://webapp0.example.com:8909
UNIX EPOCH time is now: 1585186486.72
[root@desktop0 ~]# firefox http://webapp0.example.com:8909/<code>
閱讀更多 神小威 的文章