# Having trouble thinking of a structure for Nginx+PHP setup, with multiple vhosts.

**URL:** <https://forum.ansible.com/t/having-trouble-thinking-of-a-structure-for-nginx-php-setup-with-multiple-vhosts/13506>\
**Category:** Ansible Project\
**Created:** [September 19, 2013, 6:52am UTC](https://forum.ansible.com/t/having-trouble-thinking-of-a-structure-for-nginx-php-setup-with-multiple-vhosts/13506 "2013-09-19T06:52:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dan7](https://avatars.discourse-cdn.com/v4/letter/d/3bc359/32.png) [@Dan7](https://forum.ansible.com/u/Dan7)\
**Post date:** [September 19, 2013, 6:52am UTC](https://forum.ansible.com/t/having-trouble-thinking-of-a-structure-for-nginx-php-setup-with-multiple-vhosts/13506/1 "2013-09-19T06:52:37Z")

</div>

Hey,

I have several servers and each server runs Nginx and Php-fpm.

On each server I have several Vhosts, each Vhost (or a group of several) is owned by a linux user and is tied to a Php-fpm tool.

I think that I need to have the following roles:

- User
- Nginx Vhost
- Php-fpm pool

My goal is to be able to add/remove vhosts and php pools using config file. Eventually, I want to have the following files set:  
/etc/nginx/sites-enabled/{{ vhost }}  
/etc/php5/fpm/pool.d/{{ username}}.{{ poolname }}.conf  
/home/{{ username }}/{{ vhost }}/public

The problem is that I’m very confused of how to structure it.

One way of doing it, is to define my physical servers as [groups] and the hosts as my vhosts. Then I can set a group var that will use the same connection settings for all the hosts/vhosts.

For each host/vhost I’ll set a var that will indicate it’s linux user and a var for the php pool. Then the playbook will load var files according to the user and pool.

Is that a good idea? Is there another way of doing it?

Is it possible to define a JSON var and then iterate it inside a playbook?

Thanks for reading 🙂

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [September 20, 2013, 1:31am UTC](https://forum.ansible.com/t/having-trouble-thinking-of-a-structure-for-nginx-php-setup-with-multiple-vhosts/13506/2 "2013-09-20T01:31:11Z")

</div>

Ansible variables are defined in YAML, not JSON.

No, hosts should be actual things you should SSH to and not Apache vhosts.

You may want to manage them with parameterized roles though, and have a role to configure each vhost or a generic role to set up a vhost, etc.

---

<div class="post-metadata">

**Author:** ![Dan7](https://avatars.discourse-cdn.com/v4/letter/d/3bc359/32.png) [@Dan7](https://forum.ansible.com/u/Dan7)\
**Post date:** [September 20, 2013, 9:52am UTC](https://forum.ansible.com/t/having-trouble-thinking-of-a-structure-for-nginx-php-setup-with-multiple-vhosts/13506/3 "2013-09-20T09:52:45Z")

</div>

Thanks Michael,

I’m aware of parameterized roles, can I do with\_items on parameterized roles?

Each host may have several vhosts. So probably I’ll have a list of vhosts per server, and each vhost will have several vars.

Am I on the right direction?

Thanks.

---

<div class="post-metadata">

**Author:** ![James\_Cammarata1](https://avatars.discourse-cdn.com/v4/letter/j/d26b3c/32.png) [@James\_Cammarata1](https://forum.ansible.com/u/James_Cammarata1)\
**Post date:** [September 20, 2013, 2:16pm UTC](https://forum.ansible.com/t/having-trouble-thinking-of-a-structure-for-nginx-php-setup-with-multiple-vhosts/13506/4 "2013-09-20T14:16:56Z")

</div>

No, the best thing to do is to use the with\_items inside the role.

---

<div class="post-metadata">

**Author:** ![Alexander\_Saltanov](https://avatars.discourse-cdn.com/v4/letter/a/5f8ce5/32.png) [@Alexander\_Saltanov](https://forum.ansible.com/u/Alexander_Saltanov)\
**Post date:** [September 20, 2013, 10:11pm UTC](https://forum.ansible.com/t/having-trouble-thinking-of-a-structure-for-nginx-php-setup-with-multiple-vhosts/13506/5 "2013-09-20T22:11:40Z")

</div>

May be I’m not following best practices, but my production ansible’s nginx.yaml looks like this: [https://gist.github.com/sashka/6644589](https://gist.github.com/sashka/6644589)

I hope it’d helped.

Alexander.

---

<div class="post-metadata">

**Author:** ![Dan7](https://avatars.discourse-cdn.com/v4/letter/d/3bc359/32.png) [@Dan7](https://forum.ansible.com/u/Dan7)\
**Post date:** [September 21, 2013, 8:10am UTC](https://forum.ansible.com/t/having-trouble-thinking-of-a-structure-for-nginx-php-setup-with-multiple-vhosts/13506/6 "2013-09-21T08:10:25Z")

</div>

Thanks for your reply James.

So you’re saying that the role for vhost should deal with all the vhost configurations and not for a single vhost config? Did I get it right?

Thanks.
