Trellis + Build Nginx From Source + ngx_pagespeed = Enjoy

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

12 Likes

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

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.

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!

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.

1 Like

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

1 Like

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:

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.

1 Like

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.

Hi @RiFi2k and @deschet,

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

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

2 Likes

Any updates here? @RiFi2k

1 Like

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

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
or I just a patch - nginx-build.patch

cheers

5 Likes

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

2 Likes

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

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

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 .

1 Like

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

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.

2 Likes

Alternatively you can also try out the


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

1 Like