Skip to content

How to get Travis CI to test Nginx code including nginx.conf, vhosts and custom nginx code you have written and need to test using Travis CI's build checker.

License

Notifications You must be signed in to change notification settings

mitchellkrogza/Travis-CI-Nginx-for-Testing-Nginx-Configuration

Repository files navigation

Build Status

Template for Travis CI Testing of Nginx Configuration Files

This is a basic template for getting Travis CI's container based infrastructure to install a stable version of Nginx including Nginx-Extras and to test any scenario of Nginx.conf files and customization scripts you have written.

I actually use this a test playground for my Nginx Bad Bot Blocker - https://github.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker so it's always changing but it will give you the basics of how to properly install Nginx on Travis.

The purpose of this repository?

Travis CI is a great system for checking and testing your build's Commits, Pull Requests and Merges. Travis runs everything inside a Docker container so it's a fully contained system that you can run build tests on your GIT repository and you can't break anything outside of it.

This repository contains a simple layout for installing nginx into Travis, then loading your config files and running and number of bash commands to test your scripts.

If you pulled all your hair out already trying to get this all to work with Travis CI then you have landed in the right repository.

Travis CI does not come with Nginx pre-installed so the install needs to be scripted to tell Travis CI what to do. This script takes care of installing a stable build of nginx including nginx-extras.

If you don't even know what the heck Travis CI is read here - https://travis-ci.org/

How the installation works

All of the installation files are located in the /travis-ci directory.

The main installation is done through the install-nginx.sh bash script.

It's a simple script so it should be relatively easy to follow for anyone with a little bit of understanding of bash. The other scripts in the /travis-ci directory are basic Nginx and php-fpm configuration templates.

How to Use This

  1. Install Nginx using simple apt-get via entries in the .travis.yml file.
  2. Collect any information for the install into environment variables.
  3. Copy the configuration templates to a new directory while replacing placeholders with environment variables.
  4. Start php-fpm and Nginx with our custom configuration file instead of the default.
  5. Runs an nginx -t test to confirm Nginx is correctly configured
  6. Runs a curl against a simple php file in the /www directory.

Enjoy and hope this helps you.

If this helped you why not buy me a beer🍺