# Trellis + Build Nginx From Source + ngx_pagespeed = Enjoy

**URL:** https://discourse.roots.io/t/trellis-build-nginx-from-source-ngx-pagespeed-enjoy/6391
**Category:** trellis
**Created:** 2016-04-06T15:02:27Z
**Posts:** 20

## Post 1 by @RiFi2k — 2016-04-06T15:02:27Z

So long story short I decided last week I wanted to integrate building Nginx from source into Trellis so I could get the cache\_purge module and a few other 3rd party modules without having to manually do it everytime. Then I also at the same time got the idea that I wanted to try out the ngx\_pagespeed module because I was building it from source anyways so why not. Instead of being normal and just manually installing this rig I decided it would be fun to integrate the whole deal into Trellis and make it configurable.

Moral of the story is I’m really tired and a couple clients are probably minorly annoyed with me. But hey… at least now anyone that has ever thought it would be cool to have Pagespeed and nginx from source in Trellis can actually demo it out!

In all seriousness though it’s pretty raw and I’m sure a few things a did at 4am are certainly not play book best practices. Also if you guys see any wtf things just know I went from never really writing or releasing anything like this to going hard at something that was pretty time consuming.

Anyways the documentation I wrote will get you through it easily but it needs expanded and I included links to nginx and google pages so you can research and decide for yourselves which modules you want to build your setup with. I’ll definatly help anyone who wants a hand with it and welcome anyone who has better ideas for a few things I clearly rushed. I’ll be working on it too, but I really hope a few of you get a little use out of it.

I have provisioned at least 10 GCE instances from scratch and put 3 different sites up on a staging server and they all seem to be working with no problems so enjoy!

Haha you probably want the link now too huh, I almost forgot, that would have been classic after making you read my epic rant.

[https://github.com/RiFi2k/trellis](https://github.com/RiFi2k/trellis)

---

## Post 2 by @swalkinshaw — 2016-04-06T15:15:02Z

Awesome :thumbsup:. What are the build times like for compiling from source + some modules?

---

## Post 3 by @RiFi2k — 2016-04-06T15:18:00Z

I have in a good amount of stuff by default and I have tried it with almost all of them. It really doesn’t take me more than a few minutes longer than a normal Trellis provision maybe 5-7 mins extra if you go crazy.

---

## Post 4 by @deschet — 2016-10-25T18:49:01Z

RiFi2k, did you delete your trellis fork with PageSpeed nginx build? I’m unable to find your build-ngnx.yml in the linked repo. I might not be looking in the correct place for it. Thanks in advance!

---

## Post 5 by @RiFi2k — 2016-10-25T19:17:41Z

You know I took it down because it was super dated, and now I compile NGINX into the .deb files instead of the long build I was doing before.

If you are interested in this still I have a role that builds out NGINX from source with the ngx\_cache\_purge module, I can easily show you how to mod it for pagespeed.

I was actually just kicking around the idea of adding the pagespeed in 100% automated like I had it before.

You tell me, if you like to get your hands a little dirty (nothing hard, I can give full instructions) I can share with you what I have currently. Or if you want hands off, give me a week.

---

## Post 6 by @deschet — 2016-10-25T19:35:43Z

I had built it from source using your “dated” repo. However, when I went to update Trellis to Xenial…my build fails because I reference [https://github.com/RiFi2k/server-configs-nginx.git](https://github.com/RiFi2k/server-configs-nginx.git) in my `nginx/tasks/main.yml` like so:

```
- name: Grab h5bp/server-configs-nginx
  git:
    repo: "https://github.com/RiFi2k/server-configs-nginx.git"
    dest: "{{ nginx_path }}/h5bp-server-configs"
    force: yes
```

I guess I don’t mind getting my hands “a little dirty”, I think I have everything else already configured. At least, it worked before. I’m thinking all I should need is the h5bp/server-configs-nginx. What are your thoughts?

Anyways, yes please share!

Thanks again for everything! :sunglasses:

---

## Post 7 by @RiFi2k — 2016-10-25T19:45:17Z

My server configs for nginx were a mirror of h5bp only I added in the

pagespeed on;

In the HTTP block of the nginx.conf

I’m 90% sure of this.

If you have a copy of my dated repo is there any way for you to share it with me, I could help you better. I had an unfortunate accident, my HD went splat a time back, and I was in a frenzy trying to recover some stuff and in my not paying attention I deleted that pagespeed repo of Trellis because I for some reason thought it was my straight clone of Trellis repo. I was up for like 36 hours straight…

That is actually the REAL reason it does not exist anymore :cold_sweat:

---

## Post 8 by @deschet — 2016-10-25T20:55:02Z

Understand. Losing a hard drive sucks a big one. I feel your pain…been there. :smirk:  
I sent my failed drive to a recovery company and paid $400 or so to have it recovered. Thankfully, they were able to recover all of my files.

Anyways, I have the repo but I’ll need to go through and remove all my info. It’ll take me a minute but I’ll get it to you.

---

## Post 9 by @RiFi2k — 2016-10-25T21:00:55Z

No rush at all, I will most certainly owe you one.

Once I see it again I will be able to help you more, it just kind of escapes me now how I structured it.

---

## Post 10 by @Bruno — 2016-11-01T12:17:05Z

Hi @RiFi2k and @deschet,

I’m also interested in implementing ngx\_pagespeed into my build. Do you still have that mod laying around?

---

## Post 11 by @RiFi2k — 2016-11-01T19:45:12Z

Hey, I am working on the fix now, but I do for sure, although I got a better build script now which does it as .deb files

---

## Post 12 by @mgargano — 2017-02-08T14:27:26Z

Any updates here? @RiFi2k

---

## Post 13 by @krishaamer — 2017-08-10T19:40:29Z

Also very much interested in this! It would be great to have this included automatically in Trellis (maybe as an option?)

---

## Post 14 by @dylanlawrence — 2017-08-21T05:42:51Z

I recently went through this and now have a successful “`nginx-build`” role for Ubuntu 16.04(xenial) working.  
All the regular configs stay in place, and all that has to change is a var in `group_vars/all/main.yml` to toggle the standard install like :

`nginx_install_type: [source | package]`.

and a dev/server.yml like:

`- { role: nginx-build, tags: [nginx], when: nginx_install_type == 'source' }`

Nearly every plugin available continues on to the complete the overall configuration (nginx.conf etc), while mine focus’ on build ONLY, well the nginx.service and init also, but it leaves the current process in place to fill out the rest.

The build time is obviously long but it would also only run - `when: flags.changed` which shouldn’t be often if ever.

I currently have several modules working, pagespeed and geoip etc.

```
nginx_modules:
  http_stub_status_module: "--with-http_stub_status_module"
  http_ssl_module: "--with-http_ssl_module"
  openssl: "--with-openssl={{ nginx_build_tmp_dir }}/openssl-{{ openssl_version }}"
  http_v2_module: "--with-http_v2_module"
  http_gzip_static_module: "--with-http_gzip_static_module"
  upload_progress_module: "--add-module={{ nginx_build_tmp_dir }}/nginx-upload-progress-module-{{nginx_upload_progress_version}}"
  ipv6_module: "--with-ipv6"
  google_perftools_module: "--with-google_perftools_module"
  http_auth_request_module: "--with-http_auth_request_module"
  headers_more_module: "--add-module={{ nginx_build_tmp_dir }}/headers-more-nginx-module-{{nginx_headers_more_version}}"
  http_echo_module: "--add-module={{ nginx_build_tmp_dir }}/echo-nginx-module-{{nginx_echo_version}}"
  http_real_ip_module: "--with-http_realip_module"
  naxsi_module: "--add-module={{ nginx_build_tmp_dir }}/naxsi-{{nginx_naxsi_version}}/naxsi_src"
  ngx_pagespeed: "--add-module={{ nginx_build_tmp_dir }}/ngx_pagespeed-{{nginx_ngx_pagespeed_version}}"
  http_geoip_module: "--with-http_geoip_module"
```

Have a look, I’m sure it can use a good cleanup and also the other versions added etc.

[https://github.com/dylanlawrence/trellis](https://github.com/dylanlawrence/trellis)  
or I just a patch - [nginx-build.patch](https://github.com/dylanlawrence/trellis/blob/master/nginx-build.patch)

cheers

---

## Post 15 by @dylanlawrence — 2017-08-21T17:21:43Z

Update: I had to fix some dumb last minute changes since this post, sorry if I had anyone scratching their head.

---

## Post 16 by @strarsis — 2017-09-02T19:10:37Z

@dylanlawrence: Will this be eventually merged into trellis repository so it can be just enabled by an option?

---

## Post 17 by @dylanlawrence — 2017-09-02T20:09:09Z

I’m not sure I see this as part of the core options as it may open up too many potential pitfalls, complaints of slowness etc. I could see this as a galaxy role in your `requirements.yml`, or what is referred to in trellis as a [“User contributed Extensions”](https://roots.io/trellis/docs/user-contributed-extensions/).

I would like to see 1 small change to trellis to allow this to turn off nignx by package, so I can turn on by source, the rest can remain untouched .

---

## Post 18 by @strarsis — 2017-09-02T22:05:17Z

@dylanlawrence: Yes, an User contributed Trellis Extension would be awesome!

---

## Post 19 by @dylanlawrence — 2017-09-03T00:39:17Z

[https://galaxy.ansible.com/dylanlawrence/trellis-nginx-build/](https://galaxy.ansible.com/dylanlawrence/trellis-nginx-build/)

**Update**  
This is working for me actually, other then for some reason nginx needed to be restarted, which is probably a minor change.

---

## Post 20 by @strarsis — 2018-03-18T13:10:16Z

Alternatively you can also try out the

> **[ANXS/nginx](https://github.com/ANXS/nginx)**
>
> nginx - A fairly flexible and feature full Ansible role for the NGINX web server.

  
ansible role which defaults look basically the same (so it could be used as a drop-in replacement, too).
