After enabling reverse proxy, the visitor's source address is not accurate, which request header should be added.

📅 October 9, 2026 👁️ 15

After the site is equipped with a reverse proxy, the visitor address and domain recorded by the backend are incorrect. What request headers need to be supplemented in the proxy layer? The two items to be supplemented are Host and X-Forwarded-For.The document of the proxy module is very clear, by default, the original request's Host and Connection headers will not be passed to the proxy server, so the backend sees the address of the proxy machine and the service name in the proxy configuration;The visitor's source address needs to be restored, which requires appending the client address to X-Forwarded-For and passing the original domain to Host using a variable.

First, see which address the program gets

Troubleshooting starts from the log, not from the configuration. Look at the client address recorded in the backend access log: If all request addresses point to the same internal network machine, it means that the program reads the connection address between the proxy and the program, not the real visitor address.

Similarly, confirm the domain name. If the domain name in the background records is displayed as a service name or proxy domain, rather than the actual domain name visited by the visitor, it means that Host did not pass the original request correctly. These two phenomena often occur together, but the causes are two separate configurations, which are handled separately.

What fields are not passed by default?

The default agent module does not pass through the original Host nor Connection. The consequence of the former is that the backend does not know which domain the visitor's request is directed to, which is particularly critical in multi-site domain分流;the default handling of the latter is actually a good thing, because the reuse and shutdown signals of the connection should be managed by the agent layer itself.

It should be noted that there are two ways to set the value of Host. One way is to pass the Host header from the client's request as is, but if there is no such header in the request, nothing will be passed through; for this reason, the document suggests using the $host variable - its value is equal to the service name in the request header when there is one, and falls back to the main service name in the configuration when missing. For public websites, the latter is more stable.

Request Headers Default whether to pass through The phenomenon after missing Key points of writing in the proxy layer
Host Not passing through The backend recognizes the wrong domain name, causing multiple sites to jump to the wrong site Pass the original domain name through a variable, and fall back when missing
X-Forwarded-For Set manually Visitor addresses are all recorded as proxy machines Append the client address to the existing list
Connection Not passing through Generally do not need to care Managed by the proxy layer
Protocol identifier Set manually HTTPS is identified as HTTP, causing a redirect loop Maintain consistency with the certificate offloading method

Writing in two-line configuration

The meaning of the combination variable provided by the module: $proxy_add_x_forwarded_for is to append the client address with a comma to the existing X-Forwarded-For in the request. If the request does not have this header originally, the value is equal to the client address itself. This design is crucial for multi-level proxies - directly overriding would discard the address chain already written by the upstream, appending is the only way to retain the complete chain.

The way to write the host follows the suggestions above, use a variable to pass the original domain name. After both are configured, the backend will read the visitor's source address, original domain name, and protocol, and the logic of on-site visit statistics, comment records, and domain-based routing will be consistent.

One more thing to remind you: Do not trust the X-Forwarded-For from the visitor side. When there are multiple entry points, only the appended values on the trusted proxy chain are valid, and the forged values carried by external requests must be overridden or cleaned up at the outermost entry point, otherwise the source address statistics can be manipulated manually.

What to pay attention to when multiple sites share a single entry point.

Under the multi-site scenario, the role of Host is amplified. AnQiCMS supports the management of multiple independent sites on the same backend, suitable for multi-brand and multi-theme websites. The same service often distributes requests to different sites based on domain names. At this time, if Host is missing or passed as a proxy name, it may lead to misrecognition of sites and log confusion, or even route visitors to the wrong brand site.

Port mapping should also be recorded. AnQiCMS listens to port 8001 by default, supports deployment methods such as Docker image, Baota panel, and regular environment deployment, and the proxy layer points to this service port. It is recommended to clarify three things in the deployment documentation: the external entry port, the target port of the proxy forwarding, and where the certificate is unloaded. If any of these are missing, the fault will manifest as an alternating appearance of 'the background cannot see the real source' and 'jumping loop', which is very costly to troubleshoot.

Reverse proxy itself has another benefit: static resources and page output are cached at the proxy layer, which can significantly alleviate the response pressure under high concurrency. The page loading speed of AnQiCMS is significantly improved compared to traditional PHP CMS, the official figure is that a single machine can handle about 5 million PV of traffic, and after adding proxy caching, the amount of requests the source station needs to handle can still be further reduced.

Common questions

What if we only supplement X-Forwarded-For but do not supplement Host?The visitor's source address is correct, but the backend still does not know the original domain name. The multi-site distribution according to the domain name will fail, and the site ownership in the logs is also not reliable.

Can the backend parse this header directly?It can be read, but the scope of trusted proxy should be limited. Trusting the first address in the header without judgment is equivalent to giving the source address to the visitor to fill in.

Why does the HTTPS site appear to have a redirect loop?It is usually because the certificate is unloaded at the proxy layer, and when forwarding to the backend, the protocol information is not transmitted together, causing the backend to think that it receives a plaintext request and forces a redirect. Simply add the protocol identifier.

Do I need to restart after changing the configuration?After modifying the proxy configuration, reload the entry service according to the normal process, and then check the logs to confirm that both the address and domain have been restored.

Related articles

The back-end login port is repeatedly attempted, what else can be done besides changing the access address?

When the back-end login port is repeatedly attempted, changing the access address only reduces the passive exposure area, but the real way to reduce the probability of success is another three layers: identity and token management, automated submission control, and high-risk operation domain switch for automated tools. This article provides executable changes for these three layers and explains the order of handling after attempts, including verification of credential rotation and backup recoverability.

2026-10-09

When opening slowly, should you first look at the program or the server, and how to divide the pot in three steps?

The website loads slowly, do not guess first whether it is a program or a server. Use three steps to divide the responsibility: first, measure the first byte time of static pages and dynamic pages separately, then find the inflection point under concurrency, and finally look at the actual resource usage rather than the configuration list. After completing the three steps, you can clearly determine whether the responsibility lies in program processing, entry configuration, or insufficient resources, and then decide whether to upgrade the program or add resources.

2026-10-09

Should the crawling rules of AI spider be written separately, and how to calculate the matching priority

The rule matching of crawling protocol has a clear sequence: the spider finds its rule group in a case-insensitive way, and falls into the wildcard group if it can't find it; the path rules take effect according to the most specific one, which is unrelated to the writing order. In the face of multiple AI crawlers with different purposes, whether to write separate rules depends on whether you want to distinguish training crawling from question and answer reference crawling. This article provides the method of judgment and configuration sequence.

2026-10-09

The lastmod in the sitemap writes the date of page modification or generation

The lastmod in the sitemap should write the last modified time of the page, not the generation time of the sitemap file itself, this is clearly written in the protocol document. This article explains the semantics of the field, what consequences will bring the date to be brushed to today when the entire site is re-generated, and what types of pages are worth writing, as well as the two pitfalls to pay attention to in format and time zone

2026-10-09

The difference between panel one-click deployment and command line deployment, where are the differences in daily maintenance actions

Use the same program to deploy with one click on the panel or configure layer by layer with the command line, only once during the installation stage, the difference lies in the four daily actions of adding new sites, certificate renewal, log rotation and backup recovery. This article compares the workload of two paths for each action and explains why it is necessary to compare the environment first before comparing the data when migrating.

2026-10-09

How should the filing number be handled when changing servers or access providers?

How to handle the filing number when changing the server of the website, the judgment standard is whether the access provider has changed: When changing the access provider, the access filing should be handled at the new access provider, and the change of materials for the same subject should go through the change filing and require bureau review. This article clarifies two actions, the impact on access during the review period, and the most easily overlooked one when multiple sites share a domain name.

2026-10-09

When automatic updates are enabled, what is the difference between the default behavior of major and minor versions?

When automatic updates are enabled, there is a big difference in the default orientation between major and minor versions: An official operation manual of a mainstream program states that most sites default to enabling automatic updates, covering four categories: core, plugins, themes, and translation files. Since version 5.6, new installations have default automatic updates for both minor and major versions. For enterprise sites, a more stable compromise is to automatically update minor versions, manually evaluate major versions, and confirm the backup range before the upgrade to include both data and static files.

2026-10-09

Should the backup take the uploaded images and static files together?

A backup of only the database will leave a very specific gap: after the restore, the article list is still there, but the images, attachments, and static resources in the main text all point to invalid addresses. The scope of a complete backup should cover both data and static files, and regular recovery drills should be conducted. The trash can only cover deleted documents and cannot replace backups; the location relationship of the backup files themselves should also be recorded with the site deployment directory and upload directory.

2026-10-09