大家好。我只是注意到从Apache到Nginx使用ProxyPass时的行为很奇怪,让我演示一下并询问是否有人遇到过类似的情况。
最小设置如下:
Apache:
LogLevel trace6
SSLProxyEngine On
SSLProxyCheckPeerName Off
SSLProxyCheckPeerCN Off
<LocationMatch "\.js$">
ProxyPassMatch https://static-assets.dev.com:4430
ProxyPassReverse https://static-assets.dev.com:4430
</LocationMatch>
Nginx:
server {
listen *:4430 default_server ssl;
ssl_certificate /etc/nginx/ssl/ssl.crt;
ssl_certificate_key /etc/nginx/ssl/ssl.key;
server_name static-assets.dev.com;
root /assets;
etag on;
gzip off;
server_tokens off;
add_header X-Hi-From-Nginx $sent_http_etag;
location / {
try_files $uri $uri/ =404;
}
}
然后在Apache日志中看到:
[Thu Feb 21 14:49:18.762737 2019] [proxy_http:trace3] [pid 895:tid 139989845219072] mod_proxy_http.c(1424): [client 172.17.0.1:40486] Status from backend: 200
[Thu Feb 21 14:49:18.762744 2019] [proxy_http:trace4] [pid 895:tid 139989845219072] mod_proxy_http.c(1099): [client 172.17.0.1:40486] Headers received from backend:
[Thu Feb 21 14:49:18.762749 2019] [proxy_http:trace4] [pid 895:tid 139989845219072] mod_proxy_http.c(1101): [client 172.17.0.1:40486] Server: nginx
[Thu Feb 21 14:49:18.762752 2019] [proxy_http:trace4] [pid 895:tid 139989845219072] mod_proxy_http.c(1101): [client 172.17.0.1:40486] Date: Thu, 21 Feb 2019 06:49:18 GMT
[Thu Feb 21 14:49:18.762759 2019] [proxy_http:trace4] [pid 895:tid 139989845219072] mod_proxy_http.c(1101): [client 172.17.0.1:40486] Content-Type: application/javascript
[Thu Feb 21 14:49:18.762762 2019] [proxy_http:trace4] [pid 895:tid 139989845219072] mod_proxy_http.c(1101): [client 172.17.0.1:40486] Content-Length: 1130146
[Thu Feb 21 14:49:18.762765 2019] [proxy_http:trace4] [pid 895:tid 139989845219072] mod_proxy_http.c(1101): [client 172.17.0.1:40486] Last-Modified: Mon, 18 Feb 2019 05:11:04 GMT
[Thu Feb 21 14:49:18.762768 2019] [proxy_http:trace4] [pid 895:tid 139989845219072] mod_proxy_http.c(1101): [client 172.17.0.1:40486] Connection: keep-alive
[Thu Feb 21 14:49:18.762771 2019] [proxy_http:trace4] [pid 895:tid 139989845219072] mod_proxy_http.c(1101): [client 172.17.0.1:40486] ETag: "5c6a3e68-113ea2"
[Thu Feb 21 14:49:18.762773 2019] [proxy_http:trace4] [pid 895:tid 139989845219072] mod_proxy_http.c(1101): [client 172.17.0.1:40486] X-Hi-From-Nginx: "5c6a3e68-113ea2"
[Thu Feb 21 14:49:18.762776 2019] [proxy_http:trace4] [pid 895:tid 139989845219072] mod_proxy_http.c(1101): [client 172.17.0.1:40486] Accept-Ranges: bytes
[Thu Feb 21 14:49:18.762783 2019] [proxy_http:trace3] [pid 895:tid 139989845219072] mod_proxy_http.c(1695): [client 172.17.0.1:40486] start body send
[Thu Feb 21 14:49:18.762837 2019] [http:trace3] [pid 895:tid 139989845219072] http_filters.c(1129): [client 172.17.0.1:40486] Response sent with status 200, headers:
[Thu Feb 21 14:49:18.762841 2019] [http:trace5] [pid 895:tid 139989845219072] http_filters.c(1136): [client 172.17.0.1:40486] Date: Thu, 21 Feb 2019 06:49:18 GMT
[Thu Feb 21 14:49:18.762844 2019] [http:trace5] [pid 895:tid 139989845219072] http_filters.c(1139): [client 172.17.0.1:40486] Server: nginx
[Thu Feb 21 14:49:18.762847 2019] [http:trace4] [pid 895:tid 139989845219072] http_filters.c(958): [client 172.17.0.1:40486] Content-Type: application/javascript
[Thu Feb 21 14:49:18.762849 2019] [http:trace4] [pid 895:tid 139989845219072] http_filters.c(958): [client 172.17.0.1:40486] Content-Length: 1130146
[Thu Feb 21 14:49:18.762852 2019] [http:trace4] [pid 895:tid 139989845219072] http_filters.c(958): [client 172.17.0.1:40486] Last-Modified: Mon, 18 Feb 2019 05:11:04 GMT
[Thu Feb 21 14:49:18.762854 2019] [http:trace4] [pid 895:tid 139989845219072] http_filters.c(958): [client 172.17.0.1:40486] X-Hi-From-Nginx: \\"5c6a3e68-113ea2\\"
[Thu Feb 21 14:49:18.762857 2019] [http:trace4] [pid 895:tid 139989845219072] http_filters.c(958): [client 172.17.0.1:40486] Accept-Ranges: bytes
[Thu Feb 21 14:49:18.762859 2019] [http:trace4] [pid 895:tid 139989845219072] http_filters.c(958): [client 172.17.0.1:40486] Vary: Accept-Encoding
所以基本上它会丢弃ETag头,但是我传递的具有相同值的自定义X-Hi-From-Nginx头没有任何问题。我读到启用gzip时Nginx可能会在ETag方面遇到一些麻烦,但是禁用它并不能改善任何事情。实际上,很明显问题出在Apache端,因为Nginx按预期发送了所有标头。
这是我正在使用的软件(通过Docker):
root@7ac07b106612:/bootstrap# nginx -v
nginx version: nginx/1.10.3 (Ubuntu)
root@7ac07b106612:/bootstrap# apache2ctl -v
Server version: Apache/2.4.18 (Ubuntu)
Server built: 2018-06-07T19:43:03
第二天更新。.
我实际上设法使用expr设置了一个自定义标头,如下所示:
Header always set X-Apache-ETag "expr=%{resp:x-nginx-etag}"
Header always set ETag "expr=%{resp:x-nginx-etag}"
但是,它仅设置“ X-Apache-ETag”标头,而ETag仍被丢弃。它开始看起来像是一些错误。
> GET /dist/js/vendor.js HTTP/1.1
> Host: dev.com
> User-Agent: curl/7.53.0
> Accept: */*
> Accept-encoding: br
>
{ [5 bytes data]
< HTTP/1.1 200 OK
< Date: Fri, 22 Feb 2019 04:55:10 GMT
< Server: nginx
< X-Apache-ETag: "5c6f3469-4ad21"
< Content-Type: application/javascript
< Content-Length: 306465
< Last-Modified: Thu, 21 Feb 2019 23:29:45 GMT
< X-Nginx-Etag: "5c6f3469-4ad21"
< Accept-Ranges: bytes
< Vary: Accept-Encoding
更新#2。很少有更多细节。.我看到它在“状态为200的响应发送,标头:”附近显示“ http_filters.c”,因此我开始用google搜索该文件的源。我发现的是here:
/*
* Now remove any ETag response header field if earlier processing
* says so (such as a 'FileETag None' directive).
*/
if (apr_table_get(r->notes, "no-etag") != NULL) {
apr_table_unset(r->headers_out, "ETag");
}
不知道为什么这种情况会触发,因为我的配置中没有“ FileETag None”。而且即使我添加“ FileETag MTime Size”也无济于事。
答案 0 :(得分:0)
更新#3 ..
我认为这是由加载的“ include”模块引起的。它具有此特定的SSIETag伪指令,默认情况下将其设置为“关闭”-基于导致“无标签”注释并最终使标题消失的描述。
在上下文中将其设置为“ On”并没有多大帮助,但是完全禁用“ include”模块确实有帮助,所以这是罪魁祸首。