如何在Nginx中设置海量动态虚拟主机? [英] How to setup mass dynamic virtual hosts in nginx?

查看:109
本文介绍了如何在Nginx中设置海量动态虚拟主机?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试与nginx玩了大约一个小时,以尝试设置大量动态虚拟主机. 如果您曾经用过Apache,那么您就会明白我的意思.

Been playing with nginx for about an hour trying to setup mass dynamic virtual hosts. If you ever done it in apache you know what I mean.

目标是为办公室中的少数人(超过50个)提供动态子域

Goal is to have dynamic subdomains for few people in the office (more than 50)

推荐答案

您将需要一些脚本知识才能将它们组合在一起.我会使用PHP,但是如果您擅长bash脚本编写,请使用它.我会这样:

You will need some scripting knowledge to put this together. I would use PHP, but if you are good in bash scripting use that. I would do it like this:

  1. 首先创建一些文件夹(/usr/local/etc/nginx/domain.com/).

在主要的nginx.conf文件中添加命令: include/usr/local/etc/nginx/domain.com/*.conf;

In main nginx.conf add command : include /usr/local/etc/nginx/domain.com/*.conf;

此文件夹中的每个文件都应使用不同的虚拟主机名subdomain.conf.

Every file in this folder should be different vhost names subdomain.conf.

您无需重启Nginx服务器即可使配置生效,只需重新加载它即可:/usr/local/etc/rc.d/nginx reload >

You do not need to restart nginx server for config to take action, you only need to reload it : /usr/local/etc/rc.d/nginx reload

或者您只能制作一个conf文件,在其中应设置所有虚拟主机.这样可能更好,因此nginx不需要加载50个文件,而只需加载一个....

OR you can make only one conf file, where all vhosts should be set. This is probably better so that nginx doesn't need to load up 50 files, but only one....

如果您在脚本编写方面遇到问题,请询问有关此问题...

IF you have problems with scripting, then ask question about that...

这篇关于如何在Nginx中设置海量动态虚拟主机?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆