# Best way to handle nginx config/vhosts

**URL:** <https://forum.ansible.com/t/best-way-to-handle-nginx-config-vhosts/22228>\
**Category:** Ansible Project\
**Created:** [August 6, 2016, 6:47pm UTC](https://forum.ansible.com/t/best-way-to-handle-nginx-config-vhosts/22228 "2016-08-06T18:47:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![michaeleaton](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@michaeleaton](https://forum.ansible.com/u/michaeleaton)\
**Post date:** [August 6, 2016, 6:47pm UTC](https://forum.ansible.com/t/best-way-to-handle-nginx-config-vhosts/22228/1 "2016-08-06T18:47:00Z")

</div>

So I’m trying to find a role/create a role for my Ansible config to configure nginx.

Here’s how it currently (manually!) works:

I have numerous nginx conf files for each website that I host on this machine.

[api.p123.domain.com](http://api.p123.domain.com)

[webapi.p123.domain.com](http://webapi.p123.domain.com)

[webapi.p124.domain.com](http://webapi.p124.domain.com)

etc

API is the function, what it’s for etc, p123 is the ‘platform’ and .domain.com is well… the domain…

The configuration for [api.p123.domain.com](http://api.p123.domain.com):

```auto
#main server block - api.p123.domain.com
server {

    listen 80;
    server_name api.p123.domain.com;

location / {

    #deny all access to root http://api.p123.domain.com/
    deny all;
 }

location ~* /endpoint1 {

    proxy_pass http://api.p123.domain.com;

    include include/general/proxy_common.conf;

    access_log /var/log/nginx/api.p123.domain.com/endpoint1.access.log main;
    error_log /var/log/nginx/api.p123.domain.com/endpoint1.error.log info;

 }

location ~* /endpoint2 {

    proxy_pass http://api.p123.domain.com;

    include include/general/proxy_common.conf;

    access_log /var/log/nginx/api.p123.domain.com/endpoint2.access.log main;
    error_log /var/log/nginx/api.p123.domain.com/endpoint2.error.log info;

 }
 access_log /var/log/nginx/api.p123.domain.com.access.log main;
 error_log /var/log/nginx/api.p123.domain.com.error.log info;

}

```

All the conf files are very similar. I’m basically asking for help/advice on how I can structure and achieve this using Ansible. Do I use templates or static files, I know I can set host\_vars but these nginx conf files could in theory go to multiple servers and there could be 20-30 platforms… etc

If you have any questions just ask. Thanks in advance!

Michael
