我的网站使用 cloudflare。它有两个部分:1 - api,使用 php 制作 2 - 前端,nuxt js 反向代理
我使用 Cloudflare 的“CF-IPCountry”标头来检测客户端国家代码。如果我直接从 Web 浏览器访问我的 API,则标头是正确的。
但是,如果我的前端向我的 API 发出服务器端渲染请求,则标头是错误的,并采用托管的国家/地区。
这是我的 Apache 配置:
<VirtualHost *:443>
ServerName mywebsite.com
ProxyPass / http://127.0.0.1:3000/
ProxyPassReverse / http://127.0.0.1:3000/
ProxyPreserveHost On
RewriteEngine On
RewriteCond %{HTTP_HOST} !^mywebsite.com$
RewriteRule ^/?(.*) https://mywebsite.com/$1 [QSA,R=301,L]
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
SSLCertificateFile /etc/letsencrypt/live/mywebsite.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/mywebsite.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
<VirtualHost *:443>
ServerName api.mywebsite.com
DocumentRoot "/var/www/mywebsite-api/public"
RewriteEngine On
RemoteIPHeader X-Forwarded-For
<Directory /var/www/mywebsite-api/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
SSLCertificateFile /etc/letsencrypt/live/mywebsite.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/mywebsite.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>