Nginx Module

Nginx is a web server, reverse proxy and mail proxy and http cache.

Usage example

The following example shows how to start Nginx.

@Rule
public NginxContainer<?> nginx = new NginxContainer<>(NGINX_IMAGE)
    .withCustomContent(tmpDirectory)
    .waitingFor(new HttpWaitStrategy());

How to add custom content to the Nginx server.

// Create a temporary dir
File contentFolder = new File(tmpDirectory);
contentFolder.mkdir();
contentFolder.deleteOnExit();

// And "hello world" HTTP file
File indexFile = new File(contentFolder, "index.html");
indexFile.deleteOnExit();
@Cleanup PrintStream printStream = new PrintStream(new FileOutputStream(indexFile));
printStream.println("<html><body>Hello World!</body></html>");

And how to query the Nginx server for the custom content added.

URL baseUrl = nginx.getBaseUrl("http", 80);

assertThat("An HTTP GET from the Nginx server returns the index.html from the custom content directory",
    responseFromNginx(baseUrl),
    containsString("Hello World!")
);

Adding this module to your project dependencies

Add the following dependency to your pom.xml/build.gradle file:

testCompile "org.testcontainers:nginx:1.15.0"
<dependency>
    <groupId>org.testcontainers</groupId>
    <artifactId>nginx</artifactId>
    <version>1.15.0</version>
    <scope>test</scope>
</dependency>