大网数据广告活动
服务器运维问答

Why is apache closing connections from remote clients for images, javascript and css files?

· 52CE 我爱测

I recently installed apache 2.4 on an openSUSE Leap 15.1 server on an local network, with php enabled. I can access html and php files from a browser on a desktop, but resources (images, css and javascript) are not loaded. After …

问题原文

原帖链接 · ptrico · CC BY-SA 4.0

I recently installed apache 2.4 on an openSUSE Leap 15.1 server on an local network, with php enabled. I can access html and php files from a browser on a desktop, but resources (images, css and javascript) are not loaded.

After investigation, it seems that the connection is closed when the browser requests these files but not html or php ones:

C:\Users\PATRICK>curl -v http://myserver/style.css
*   Trying 192.168.0.250...
* TCP_NODELAY set
* Connected to myserver (192.168.0.250) port 80 (#0)
> GET /style.css HTTP/1.1
> Host: myserver
> User-Agent: curl/7.55.1
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Tue, 05 Nov 2019 04:59:19 GMT
< Server: Apache
< Last-Modified: Wed, 30 Oct 2019 06:51:25 GMT
< ETag: "2e5-5961b2954acf9"
< Accept-Ranges: bytes
< Content-Length: 741
< Content-Type: text/css
<
* transfer closed with 741 bytes remaining to read
* Closing connection 0
curl: (18) transfer closed with 741 bytes remaining to read

This behaviour does not occur when querying from the server itself. The apache access logs seem to indicate that, from its perspective, the request was served successfully:

192.168.200.30 - - [05/Nov/2019:04:59:19 +0000] "GET /style.css HTTP/1.1" 200 741 "http://myserver/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:70.0) Gecko/20100101 Firefox/70.0"

I can't figure out what's going on.

已采纳解答

原帖链接 · ptrico · CC BY-SA 4.0

So the answer is that I needed this parameter in my Apache configuration file :

EnableSendFile Off

As the documentation reads :

This directive controls whether httpd may use the sendfile support from the kernel to transmit file contents to the client. By default, when the handling of a request requires no access to the data within a file -- for example, when delivering a static file -- Apache httpd uses sendfile to deliver the file contents without ever reading the file if the OS supports it.

It would appear this is not properly supported on the server I'm running (OpenSUSE Leap 15.1 with 4.12.14-lp151.28.20-default kernel).

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-11-05)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。