Skip to content

Conversation

@Miraeld
Copy link
Contributor

@Miraeld Miraeld commented Dec 9, 2025

Description

Fixes #7942
Change Cloudways Varnish port from 8080 to 80

  • Route PURGE requests through Nginx (port 80) instead of directly to Varnish (port 8080)
  • Ensures Nginx adds required X-Real-IP header for Cloudways' new VCL
  • Update test fixtures to reflect port change

Type of change

  • Bug fix (non-breaking change which fixes an issue).

Detailed scenario

What was tested

  • Unit tests verify the Varnish IP change (port 8080 → 80)
  • Unit tests verify X-Real-IP header injection when Varnish is running
  • Tests cover edge cases: Varnish not running, missing headers, varnishpass mode

How to test

Prerequisites:

  • Cloudways server with Varnish enabled
  • WP Rocket installed

Steps:

  • Clear cache from WP Rocket dashboard
  • Check Varnish logs to verify PURGE requests are successful
  • Confirm cache is actually cleared (visit a page, check it's regenerated)

Expected result:

  • PURGE requests should reach Varnish through Nginx (port 80) with X-Real-IP header included, allowing Cloudways VCL to properly validate and process the cache purge.

Technical description

Documentation

This pull request enhances the integration with Cloudways Varnish caching by ensuring that the correct headers and IP addresses are used during purge requests. It introduces a new method to add the X-Real-IP header when Varnish is detected, updates the default Varnish IP, and adds comprehensive tests to verify this behavior.

Cloudways Varnish integration improvements:

  • Added a new method, add_purge_headers, in Cloudways.php to inject the X-Real-IP: 127.0.0.1 header into Varnish purge requests when Varnish is running, and registered it to the rocket_varnish_purge_headers filter. [1] [2]
  • Changed the default Varnish IP from 127.0.0.1:8080 to 127.0.0.1:80 in Cloudways.php and updated related test fixtures to reflect this change. [1] [2] [3] [4] [5]

Testing improvements:

  • Added a new fixture file, addPurgeHeaders.php, with various scenarios for header injection based on Varnish status.
  • Introduced integration and unit test classes to validate the behavior of add_purge_headers under different server configurations. [1] [2]

Mandatory Checklist

Code validation

  • I validated all the Acceptance Criteria. If possible, provide screenshots or videos.
  • I triggered all changed lines of code at least once without new errors/warnings/notices.
  • I implemented built-in tests to cover the new/changed code.

Code style

  • I wrote a self-explanatory code about what it does.
  • I protected entry points against unexpected inputs.
  • I did not introduce unnecessary complexity.
  • Output messages (errors, notices, logs) are explicit enough for users to understand the issue and are actionnable.

- Route PURGE requests through Nginx (port 80) instead of directly to Varnish (port 8080)
- Ensures Nginx adds required X-Real-IP header for Cloudways' new VCL
- Update test fixtures to reflect port change

Fixes #7942
@Miraeld Miraeld requested a review from a team December 9, 2025 01:21
@Miraeld Miraeld self-assigned this Dec 9, 2025
Copilot AI review requested due to automatic review settings December 9, 2025 01:21
@Miraeld
Copy link
Contributor Author

Miraeld commented Dec 9, 2025

Special mention to @jeawhanlee , regarding this comment,
The engineer from Cloudways mentioned

set through port 80 so that all requests are routed through Nginx, ensuring the request headers—such as the real-ip header—are preserved as expected

Preserved doesn't assure that headers are added as we want, so I added a header addition in case.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a critical Varnish purge issue on Cloudways hosting by updating the integration to work with Cloudways' new VCL configuration. The fix changes the Varnish port from 8080 to 80 and adds the required X-Real-IP header to ensure PURGE requests are properly routed through Nginx.

  • Changed Cloudways Varnish IP from 127.0.0.1:8080 to 127.0.0.1:80 to route requests through Nginx
  • Added add_purge_headers() method to inject X-Real-IP header required by Cloudways' VCL
  • Comprehensive test coverage for the new header injection logic with edge cases

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
inc/ThirdParty/Hostings/Cloudways.php Updated Varnish port from 8080 to 80 and added new add_purge_headers() method to inject X-Real-IP header when Varnish is running
tests/Unit/inc/ThirdParty/Hostings/Cloudways/addPurgeHeaders.php New unit test for add_purge_headers() method using direct method invocation
tests/Integration/inc/ThirdParty/Hostings/Cloudways/addPurgeHeaders.php New integration test for add_purge_headers() using filter hook to verify WordPress integration
tests/Fixtures/inc/ThirdParty/Hostings/Cloudways/addPurgeHeaders.php New test fixture with 6 scenarios covering Varnish states and header combinations
tests/Fixtures/inc/ThirdParty/Hostings/Cloudways/varnishIP.php Updated expected Varnish IP port from 8080 to 80 across all test scenarios

@codacy-production
Copy link

codacy-production bot commented Dec 9, 2025

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
Report missing for 7666e821 100.00% (target: 50.00%)
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (7666e82) Report Missing Report Missing Report Missing
Head commit (bff588b) 41856 18877 45.10%

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#7948) 1 1 100.00%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

Footnotes

  1. Codacy didn't receive coverage data for the commit, or there was an error processing the received data. Check your integration for errors and validate that your coverage setup is correct.

@jeawhanlee
Copy link
Contributor

@Miraeld From my little findings, if you log $_SERVER['HTTP_X_REAL_IP'] on our cloudways site, you'll see it's added without purge triggered, so I'm thinking this will be the case even when purge is triggered.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Varnish Purge on Cloudways

4 participants