Apache部分请求丢失Referer信息,请求排查服务器端原因
Hey Mike, let's break down your problem step by step based on what you've shared. It's totally valid to suspect server-side issues here—especially since you confirmed the Referer should exist during your real-time testing. Let's cover the likely culprits and how to investigate them:
1. First, rule out source website edge cases
While you mentioned multiple sources have issues, it's worth quickly eliminating these common scenarios:
- Browser/extension privacy settings: Some browsers (in incognito mode) or ad-blocking extensions block Referer headers by default. But since you tested this yourself in real time, this probably doesn't apply to your specific missing logs.
noreferrerlink attributes: If the source site's links userel="noreferrer"orrel="noopener noreferrer", browsers won't send a Referer. Double-check the HTML of the links you tested to rule this out.
2. Server-side (Apache + Nginx Cache) investigation priorities
Since you're on Plesk with an Apache + Nginx reverse proxy/cache stack, most Referer loss issues here trace back to Nginx's proxy configuration or Apache's header handling.
2.1 Check Nginx's proxy header forwarding
Nginx acts as the front-end layer here, so it needs to explicitly pass the Referer header to Apache. If this is missing, Apache will never see the header:
- In Plesk, go to Domains > [Your Domain] > Apache & Nginx Settings
- Look in the Additional Nginx directives section for this line:
If it's missing, add it and save the configuration. Then restart Nginx via Tools & Settings > Services Management.proxy_set_header Referer $http_referer; - Also check Nginx's cache rules: Some cache configurations might ignore request headers like Referer, or serve cached responses without accounting for different Referer values. Ensure your cache setup doesn't strip or ignore this header.
2.2 Verify Apache's Referer handling
Apache itself could be modifying or stripping the Referer header via modules like mod_rewrite or mod_headers:
- In Plesk, go to Domains > [Your Domain] > Apache & Nginx Settings > Additional Apache directives
- Look for any rules that modify the Referer, such as:
If you find any, temporarily comment them out and test again to see if Referers start appearing in logs.Header unset Referer # Or rewrite rules targeting the Referer RewriteCond %{HTTP_REFERER} ... RewriteRule ... - Your log format already includes
"%{Referer}i", so Apache is configured to log the header correctly—this means the issue is that the header never reaches Apache in the first place.
2.3 Test bypassing Nginx directly
To isolate whether the problem is Nginx or Apache:
- Find Apache's listening port (usually 8080 on Plesk setups)
- Use
curlto send a request directly to Apache with a Referer header:curl -H "Referer: https://test-source.com" http://your-domain.com:8080/ - Check your Apache access logs. If the Referer shows up here, the problem is definitely in Nginx's proxy configuration. If it's still missing, you'll need to dig deeper into Apache's global settings.
3. Plesk-specific configuration gotchas
Plesk auto-generates configuration files, so make sure:
- You're modifying domain-specific directives (not global ones) to avoid overwrites during Plesk updates.
- After making changes, you restart both Apache and Nginx services—sometimes a single restart isn't enough.
4. Deep dive: Log Nginx's incoming requests
If you're still stuck, enable detailed logging in Nginx to confirm whether it even receives the Referer header:
- Add this log format to your domain's Additional Nginx directives:
log_format full_requests '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" "$http_user_agent"'; access_log /var/log/nginx/your-domain-full.log full_requests; - Restart Nginx, then replicate the issue.
- Check the new log file:
- If Nginx shows the Referer but Apache doesn't: Nginx isn't forwarding the header correctly (go back to step 2.1).
- If Nginx also shows "-" for Referer: The header is missing before it reaches your server—this could point to a CDN (if you use one) or network-level filtering, but since you tested in real time, this is less likely.
Final thought
Given your real-time testing confirms the Referer should exist, the most probable culprit is Nginx failing to forward the header to Apache. Start there, and work your way through the steps above—you'll likely find the fix quickly.
内容的提问来源于stack exchange,提问作者Mike

