How to use Apache Benchmark to Simulate traffic on Nginx

Where necessary, you may need to have access to a VPS server so you can follow how to implement the steps in this article.  You can get a cheaper VPS Server from Contabo with 4vCPU cores, 8GM RAM, and 32TB Bandwidth for less than $5.50 per month. Get this deal here now

Table of Contents

Cloud VPS S

$5.50 Monthly
  • 4 vCPU Cores | 8GB RAM


$15.50 Monthly
  • 6 vCPU Cores | 16GB RAM


$17.50 Monthly
  • 8 vCPU Cores | 24GB RAM

Simulating traffic on your Nginx web server is crucial for testing its performance and identifying potential bottlenecks. Apache Benchmark (ab) is a powerful tool that allows you to stress-test your server by generating a specified number of requests.

In this article, we’ll walk you through the process of using Apache Benchmark to simulate traffic on Nginx.

Step 1: Install Apache Benchmark

Before you can start using Apache Benchmark, ensure it is installed on your system. You can install it using package managers. For example, on a Debian-based system, run:

sudo apt-get install apache2-utils

It’s important to note that the Apache Benchmark tool must be installed on a separate server. This means that it shouldn’t be installed on the same machine on which your Nginx application is running.

Apache Benchmark Parameters and Options

You can customize the Apache Benchmark by using its parameters option flags to optimize the results you need. See the table below:

-n requestsTotal number of requests to perform during the test.
-c concurrencyNumber of multiple requests to perform at a time (concurrency).
-kUse HTTP KeepAlive feature.
-T content-typeSpecify the content type for POST requests.
-p post-fileFile containing data to POST.
-H custom-headerAdd a custom header to the request.
-g gnuplot-fileOutput collected data in gnuplot format.
-t timelimitMaximum number of seconds to spend on benchmarking.
-s timeoutMaximum seconds to wait for each response.
-A username:passwordSpecify username and password for basic authentication.
-SDo not display the percentage served within the time table.
-C cookie-name=valueInclude a simple cookie in the request.
-dDo not display additional debug information.
-rDon’t exit on socket receive errors.
-lAccept variable document length (useful for dynamic pages).
-g output-fileWrite gnuplot-format data to given filename.
-e csv-fileWrite results in CSV format to a given file.

This table includes some commonly used options, and you can refer to the Apache Benchmark documentation for a comprehensive list of options and their details: Apache Benchmark Documentation

Step 2: Testing Concurrent requests

Once you’ve installed Apache Benchmark, you can perform a couple of concurrent request tests:

Sending 100 concurrent requests

To send 100 concurrent requests using Apache Benchmark, you can modify the command accordingly. Here’s an example:

ab -n 100 -c 100

In this command:

  • -n 100 specifies the total number of requests to perform, which is set to 100.
  • -c 100 sets the concurrency level, meaning it will send 100 requests concurrently.

Adjust the URL and other parameters as needed for your specific testing scenario.

Sending 500 concurrent requests

To send 500 concurrent requests using Apache Benchmark, you can use the following command:

ab -n 500 -c 500

In this command:

  • -n 500 specifies the total number of requests to perform, which is set to 500.
  • -c 500 sets the concurrency level, meaning it will send 500 requests concurrently.

Make sure to replace “” with the actual URL of your Nginx server. Adjust other parameters as needed for your testing requirements.

Sending 1000 concurrent requests

To send 1000 concurrent requests using Apache Benchmark, you can use the following command:

ab -n 1000 -c 1000

In this command:

  • -n 1000 specifies the total number of requests to perform, which is set to 1000.
  • -c 1000 sets the concurrency level, meaning it will send 1000 requests concurrently.

Ensure to replace “” with the actual URL of your Nginx server. Adjust other parameters as needed for your testing scenario.

Step 3: Customizing Requests

Customizing requests in Apache Benchmark involves specifying additional parameters to tailor the testing conditions according to your requirements. Here are some examples of how you can customize requests:

Include specific file in the requests

To include a specific file in your requests, use the following command:

ab -n 200 -c 20

Customizing Request Type

You can specify the request type, such as GET or POST, using the -k option for HTTPS:

ab -n 500 -c 50 -k -T 'application/x-www-form-urlencoded' -p post_data.txt

In this example, -T 'application/x-www-form-urlencoded' sets the content type for a POST request, and -p post_data.txt includes the data from the specified file in the request.

Customizing Headers

To add custom headers to your requests, use the -H option:

ab -n 200 -c 20 -H 'Authorization: Bearer your_token'

Replace 'Authorization: Bearer your_token' with the specific header you want to include.

Customizing Query Parameters

You can customize query parameters by appending them to the URL:

ab -n 300 -c 30 "¶m2=value2"

Adjust the parameters and values according to your testing needs.

Combining Customizations

Combine different customizations for more complex scenarios:

ab -n 1000 -c 100 -T 'application/json' -H 'Authorization: Basic base64_encoded_credentials' -p post_data.json

This example combines setting the content type, adding an authorization header, and including data from a JSON file in a POST request.

Step 4: Generate HTML Report

Apache Benchmark can generate an HTML report for a more detailed analysis. Execute the following command:

ab -n 500 -c 50 -g output.html

This command generates an HTML file named “output.html” containing detailed statistics and graphs.

Step 5: Testing SSL/TLS

To simulate traffic on an Nginx server using HTTPS, include the -k option:

ab -n 100 -c 10 -k

Step 6: Authentication

If your Nginx server requires authentication, use the following command:

ab -n 50 -c 5 -A username:password

Replace “username” and “password” with your credentials.


Simulating traffic on your Nginx server with Apache Benchmark is an effective way to evaluate its performance under different conditions. Following the steps outlined in this article and customizing the commands according to your needs can help you gain valuable insights into your server’s capabilities and optimize its configuration for optimal performance.

Hire us to handle what you want

Hire us through our Fiverr Profile and leave all the complicated & technical stuff to us. Here are some of the things we can do for you:

  • Website migration, troubleshooting, and maintenance.
  • Server & application deployment, scaling, troubleshooting, and maintenance
  • Deployment of Kubernetes, Docker, Cloudron, Ant Media, Apache, Nginx,  OpenVPN, cPanel, WHMCS, WordPress, and more
  • Everything you need on AWS, IBM Cloud, GCP, Azure, Oracle Cloud, Alibaba Cloud, Linode, Contabo, DigitalOcean, Ionos, Vultr, GoDaddy, HostGator, Namecheap, DreamHost, and more.

We will design, configure, deploy, or troubleshoot anything you want. Starting from $10, we will get your job done in the shortest time possible. Your payment is safe with Fiverr as we will only be paid once your project is completed.