我有一个从我的网站上的相对urlredirect到其他绝对url的dynamic列表:
my_website_url_1 --> other_website_url_1 ... my_website_url_N --> other_website_url_N
该列表由数百个条目组成,每天更改数次。
(实际列表在数据库中,但可以在文本文件或任何forms的舒适。)
“我的网站”是一个nginx服务器。
我正在寻找一个强大的解决scheme,将redirect列表更改部署到nginx服务器而不中断服务。
有什么build议?
用别的东西replacenginx是一个选项。
我很早以前就为此写了一个小机架应用程序。 你可以在http://github.com/minhajuddin/redirector查看
自述文件:
一个简单的机架应用程序,使多个领域的redirect轻而易举。
要configuration应用程序,您只需编辑config.yaml文件,以下是一个示例configuration文件:
cosmicvent.net: # <== This is the host name of the domain which you want to redirect status: 302 # <== status code with which it is redirected, 302 for temporary redirects, 301 for permanent redirects location: 'http://cosmicvent.com' # <== the domain which it is redirected *to* 'localhost:3030': status: 301 location: 'http://cosmicvent.com:3030'
我不确定在你的情况下最好的select是什么。 我想你可以创build一个cron作业,生成你的nginxconfiguration的一部分,然后重新加载,但这对我来说似乎是一个危险的黑客。
根据您在相对URL上获得多less负载,您可以让应用程序代码触发redirect。 例如,如果您使用的是PHP,请检查传入的URL以查看它是否是您的redirect表,如果是,则将HTTPredirect发送回规范URL。
一个想法是有一个数据库(MySQL或你有什么)表,你可以填充你的redirect。 每隔一小时左右,cron就可以启动一个脚本来检查这个表格,看看是否有上次运行的新条目,然后根据它在表格中find的内容生成一个新的nginxconfiguration。
我build议使用像Ruby + ERB的东西来完成这个。
之后,它可以针对nginx发出重新加载以避免服务中断。