如何配置Apache服务器/ crontab / bash文件以允许在一天中的特定时间访问和/或从特定IP访问?

问题描述 投票:0回答:1

我正在尝试由我的教练进行锻炼。我们的任务是设置可以在mon-fri / 1-5访问的VirtualHost。最重要的是,我们必须随时允许通过IP“ XX.XX.XX.XXX”访问该网站。

当前crontab:

* 13 * * 1-5 root apachectl start
* 17 * * 1-5 root apachectl stop
* * * * * root ./bash

Bash文件:

currIP=$(hostname -I)
case "$currIP" in
        *XX.XX.XX.XXX*)
              ???????
;;
esac

有人可以向我解释如何将这个站点提供给IP,而不是立即向所有人提供吗?

谢谢!

linux bash apache cron virtualhost
1个回答
0
投票

让我们说这是您的配置文件。

/etc/apache2/httpd.conf

运行这些命令:

sudo cp /etc/apache2/httpd.conf all.conf
sudo cp /etc/apache2/httpd.conf restricted.conf

现在在系统中的某个位置创建此脚本:

#!/bin/bash

[[ "$1" = "all" ]] && { ln -s --force /etc/apache2/all.conf /etc/apache2/httpd.conf ;}
[[ "$1" = "restricted" ]] && { ln -s --force /etc/apache2/restricted.conf /etc/apache2/httpd.conf ;}
sudo systemctl restart httpd

现在修改/ etc / apache2 / restricted.conf以按IP过滤请求。您可以在此处找到有关此信息:https://httpd.apache.org/docs/2.4/es/mod/mod_authz_core.html#require

现在将根cron设置为:

sudo crontab -e

然后在其中添加此:

* 13 * * 1-5 /path/to/your/script.sh "all"
* 17 * * 1-5 /path/to/your/script.sh "restricted"

并且要开心!

© www.soinside.com 2019 - 2024. All rights reserved.