How to setup mass dynamic virtual hosts in nginx?

前端 未结 7 1981
借酒劲吻你
借酒劲吻你 2021-01-30 09:42

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.

Goal is to have dynamic subdom

7条回答
  •  逝去的感伤
    2021-01-30 10:15

    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. First create some folder (/usr/local/etc/nginx/domain.com/).

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

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

    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

    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...

提交回复
热议问题