AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题

问题[apache-2.4](server)

Martin Hope
therobyouknow
Asked: 2025-03-22 06:15:12 +0800 CST

为什么 Apache 正在监听启用 SSL 的服务器端口 80?

  • 5

我已经为端口 80 的域设置了一个虚拟主机:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName thesolentmetropolitan.com
    DocumentRoot /var/www/10/thesolentmetropolitan.com/deployment_environments/live/docroot
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    <Directory "/var/www/thesolentmetropolitan.com/docroot">
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
    </Directory>
</VirtualHost>

访问该网站的结果是:

错误的请求

您的浏览器发送了一个此服务器无法理解的请求。原因:您正在向启用 SSL 的服务器端口发送纯 HTTP 消息。请使用 HTTPS 方案访问此 URL。Apache/2.4.58 (Ubuntu) 服务器位于127.0.1.1 端口 80

我禁用了所有其他 vhost 排列 https http、www 和不带 www。

我检查了以下内容(我不确定如何处理以下内容):

sudo lsof -i -n | grep https
apache2   520640            root    6u  IPv6 4829014      0t0  TCP *:https (LISTEN)
apache2   520645        www-data    6u  IPv6 4829014      0t0  TCP *:https (LISTEN)
apache2   520662        www-data    6u  IPv6 4829014      0t0  TCP *:https (LISTEN)
apache2   520705        www-data    6u  IPv6 4829014      0t0  TCP *:https (LISTEN)
apache2   520706        www-data    6u  IPv6 4829014      0t0  TCP *:https (LISTEN)
apache2   520707        www-data    6u  IPv6 4829014      0t0  TCP *:https (LISTEN)
apache2   520708        www-data    6u  IPv6 4829014      0t0  TCP *:https (LISTEN)
apache2   520741        www-data    6u  IPv6 4829014      0t0  TCP *:https (LISTEN)
apache2   520743        www-data    6u  IPv6 4829014      0t0  TCP *:https (LISTEN)
apache2   520981        www-data    6u  IPv6 4829014      0t0  TCP *:https (LISTEN)
apache2   520982        www-data    6u  IPv6 4829014      0t0  TCP *:https (LISTEN)

并检查了其他虚拟主机。

root@server03:/etc/apache2/sites-available# apachectl -S
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
VirtualHost configuration:
*:443                  is a NameVirtualHost
         default server drupalsolent.dev (/etc/apache2/sites-enabled/drupalsolent.dev-le-ssl.conf:2)
         port 443 namevhost drupalsolent.dev (/etc/apache2/sites-enabled/drupalsolent.dev-le-ssl.conf:2)
         port 443 namevhost www.drupalsolent.dev (/etc/apache2/sites-enabled/drupalsolent.dev-le-ssl.conf:21)
         port 443 namevhost eval1.labs.drupalsolent.dev (/etc/apache2/sites-enabled/eval1.labs.drupalsolent.dev-le-ssl.conf:2)
         port 443 namevhost internationalgospelchoir.uk (/etc/apache2/sites-enabled/internationalgospelchoir.uk-le-ssl.conf:2)
         port 443 namevhost staging.internationalgospelchoir.uk (/etc/apache2/sites-enabled/staging.internationalgospelchoir.uk-le-ssl.conf:2)
         port 443 namevhost www.internationalgospelchoir.uk (/etc/apache2/sites-enabled/www.internationalgospelchoir.uk-le-ssl.conf:2)
*:80                   is a NameVirtualHost
         default server drupalsolent.dev (/etc/apache2/sites-enabled/drupalsolent.dev.conf:1)
         port 80 namevhost drupalsolent.dev (/etc/apache2/sites-enabled/drupalsolent.dev.conf:1)
         port 80 namevhost eval1.labs.drupalsolent.dev (/etc/apache2/sites-enabled/eval1.labs.drupalsolent.dev.conf:1)
         port 80 namevhost internationalgospelchoir.uk (/etc/apache2/sites-enabled/internationalgospelchoir.uk.conf:1)
         port 80 namevhost staging.internationalgospelchoir.uk (/etc/apache2/sites-enabled/staging.internationalgospelchoir.uk.conf:1)
         port 80 namevhost thesolentmetropolitan.com (/etc/apache2/sites-enabled/thesolentmetropolitan.com.conf:1)
         port 80 namevhost www.drupalsolent.dev (/etc/apache2/sites-enabled/www.drupalsolent.dev.conf:1)
         port 80 namevhost www.internationalgospelchoir.uk (/etc/apache2/sites-enabled/www.internationalgospelchoir.uk.conf:1)
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex mpm-accept: using_defaults
Mutex watchdog-callback: using_defaults
Mutex rewrite-map: using_defaults
Mutex ssl-stapling-refresh: using_defaults
Mutex ssl-stapling: using_defaults
Mutex ssl-cache: using_defaults
Mutex default: dir="/var/run/apache2/" mechanism=default
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33
Group: name="www-data" id=33
root@server03:/etc/apache2/sites-available#

其他分析信息:

root@server03:/etc/apache2/sites-available# cat drupalsolent.dev.conf
<VirtualHost *:80>
  ServerName drupalsolent.dev
  RedirectPermanent / https://drupalsolent.dev/
</VirtualHost>

我已经在不同网络上尝试过该域名:固定电话和移动电话,都出现了同样的错误,所以我想这一定是服务器上的问题。

会是什么呢?

我需要解决这个问题,因为我连接到端口 80 以便 LetsEncrypt 提供 https 证书。

感谢您的帮助。

我查看了通过 http 服务端口 443 会产生 400 错误请求错误而不是重定向,它确实有一些相似之处,但不是我想要的。

apache-2.4
  • 1 个回答
  • 108 Views
Martin Hope
FireEmerald
Asked: 2025-03-19 19:42:26 +0800 CST

如何在 apache 日志文件中获取用户发送的精确查询字符串?

  • 5

Apache%r日志格式输出:"GET /server?id=1 HTTP/2.0"。

我只需要将完全相同的查询参数值?id=1作为日志中的单独字段。

因此我尝试了这个%q选项,但不幸的是,它输出的是相同的请求:

?ReturnUrl=Example.aspx?id=1

当然,这涉及到重写,但一定有办法准确获取客户端发送的内容,对吗?怎么做?

  • 查看Apache 自定义日志格式
apache-2.4
  • 1 个回答
  • 19 Views
Martin Hope
Ben Holness
Asked: 2025-03-06 10:53:15 +0800 CST

我如何知道 LocationMatch 在 apache2 中检查什么?

  • 5

我正在使用 LocationMatch 指令来确定是否设置 CORS 标头,但无法使其正常工作。

例如,如果 URI 是/folder1/f/folder2/document1,则<LocationMatch "^/folder1/f">有效,但<LocationMatch "^/folder1/f/">不行,然而<LocationMatch "^/folder1/f.">可以。理想情况下,我会以 结尾<LocationMatch "^/folder1/f/folder2">,但这也不起作用。

我不明白为什么^/folder1/f/它不起作用。理想情况下,我希望在日志中看到它匹配的内容,以防发生我不知道的事情。

有什么方法可以将其输出到某处的日志中吗?

apache-2.4
  • 1 个回答
  • 45 Views
Martin Hope
Serge
Asked: 2025-02-14 03:24:48 +0800 CST

寻找关于使用 PHP-FPM 设置不同 PHP 错误日志文件的最终答案

  • 5

环境 - RHEL 9.5、带有服务器 MPM = 事件的 Apache 2.4.62、带有 PHP-FPM 的 PHP 7.4.33

前言 - 以前我们可以在每个 .HTACCESS 文件中使用这样的设置来为每个虚拟主机设置如下指令

php_flag  log_errors on
php_value error_reporting 22517 # produced by - echo E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_WARNING & ~E_NOTICE ; 
php_value error_log  /var/log/php_errors/example1_com_errors.log

这非常合乎逻辑且方便,因为一个网站处于生产模式,需要自己的错误报告级别,而另一个网站处于开发模式 - 需要另一个错误报告级别。更不用说我们可以将错误存储在不同的文件中。

现在我们有以下因素

  1. EL-8 现在默认使用 php-fpm(如果切换到 prefork,mod_php 仍然可用)- 而 EL-9 仅提供 php-fpm(完整答案来自StackOverflow 的 Remi Colet)
  2. 因此,对于 EL-9,我们必须在“mpm_event”模式下使用带有 php-fpm 的 Apache
  3. 由于错误“无效命令‘php_flag’,可能是拼写错误或由服务器配置中未包含的模块定义”,我们无法将 php_value 或 php_flag 与 Apache mpm_event 模块一起使用。
  4. 同时 - 建议使用 PHP-FPM“.user.ini”文件,但不允许上述要求的可能性!请参阅https://www.php.net/manual/en/configuration.file.per-user.php - .user.ini 样式的 INI 文件中仅可识别具有 INI_PERDIR 和 INI_USER 模式的 INI 设置。

我很惊讶,在没有网络社区的解决方案的情况下,竟然有如此方便和必要的功能。也许某个地方有“隐藏的解决方案”,但我没有找到。谷歌搜索没有太大帮助,主要返回关于旧设置方式的相同版权式答案。

我的问题是- 在上述环境(mpm_event、PHP-FPM 等)下 - 我们能否以某种方式设置相同的功能 -为每个虚拟主机设置自己的 php 错误级别并存储在自己的 php 错误日志文件中? 感谢您的意见和尝试提示,

apache-2.4
  • 1 个回答
  • 33 Views
Martin Hope
olivierg
Asked: 2025-02-07 22:04:53 +0800 CST

Apache 反向代理:打印后端返回的错误,而不仅仅是“错误 500”

  • 6

我有一个 apache 服务器充当 web 服务的反向代理,其配置如下:

<VirtualHost *:18010>

 SSLEngine on
 ProxyRequests off
 SSLProxyEngine on
 ProxyPass / https://backend.url:4445/
 ProxyPassReverse / https://backend.url:4445/
 SSLVerifyClient require
 SSLVerifyDepth 10
 SSLCACertificateFile ssl/cacerts.pem

</VirtualHost>

运行良好。但是,当“客户端”针对 URL 后面运行的 WebService 运行查询时,如果后端响应错误,则代理仅显示存在错误 500,例如:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>500 Internal Server Error</title>
</head><body>
<h1>Internal Server Error</h1>
<p>The server encountered an internal error or
misconfiguration and was unable to complete
your request.</p>
<p>Please contact the server administrator at
 [email protected] to inform them of the time this error occurred,
 and the actions you performed just before this error.</p>
<p>More information about this error may be available
in the server error log.</p>
</body></html>

而当“直接”(不通过代理)查询WebService时,我们可以看到服务器返回的“真实”错误,例如:

Error 500: javax.servlet.ServletException: org.codehaus.jackson.map.exc.UnrecognizedPropertyException: Unrecognized field &quot;test&quot; &#40;Class iseries.wsbeans.avews10.PrecheckInput&#41;, not marked
 at [Source: com.ibm.ws.webcontainer.srt.SRTInputStream@6bd1f156&#59; line: 1, column: 11] &#40;through reference chain: iseries.wsbeans.avews10.PrecheckPaymentInput[&quot;test&quot;]&#41;

所以我的问题是:是否有一个选项可以添加 apache 配置,以便它返回后端返回的完整错误,而不仅仅是错误 500?

再次感谢问候,

apache-2.4
  • 1 个回答
  • 64 Views
Martin Hope
winck
Asked: 2025-01-26 04:11:23 +0800 CST

如果未找到,则提供静态文件和代理

  • 7

我正在尝试配置一个 vhost 来与代理一起工作,但前提是请求不是静态文件——在这种情况下,我希望 Apache 能够为其提供服务。以下是我使用的:

<VirtualHost *:80>
    ServerName app.local
    DocumentRoot "/app/static"

    # Serve static files
    <Directory "/app/static">
        Require all granted
        Options Indexes FollowSymLinks
        AllowOverride None
    </Directory>

    RewriteEngine On

    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^ - [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^/(.*) http://localhost:8000/$1 [P,L,QSA]

    ProxyPreserveHost On
    ProxyPass / http://localhost:8000/
    ProxyPassReverse / http://localhost:8000/
</VirtualHost>

但是,如果我尝试获取app.local/style.css,那么尽管文件存在,但该请求仍会被代理(我在代理服务器日志中看到它)/app/static/style.css。我该如何让它提供这些文件?

apache-2.4
  • 1 个回答
  • 75 Views
Martin Hope
FalcoGer
Asked: 2025-01-23 02:49:20 +0800 CST

apache2 在提供大型静态文件时内存不足

  • 6

我正在运行一个带有多个虚拟主机的 apache2 服务器。我在资源相当受限的 Raspberry Pi 4 上运行它。特别是 RAM 非常紧张(4GB)。流量并不多,我主要用它来托管 nextcloud、自定义流媒体网站和一些静态文件。

问题在于静态文件。每当我或其他任何人下载文件时,似乎整个文件都加载到了 RAM 中。对于小文件来说这不是问题,但任何大于 500MB 的文件都会引起严重问题,通常会填满 SWAP 并最终导致 Apache 的 OOM 终止。

我无论如何也想不出如何让它简单地从磁盘流式传输文件,而不是在发送之前将它们缓存在内存中。如果你在一台合适的服务器上有 128GB 的​​ RAM,这可能是可行的,但它在我可怜的 PI 上让我很头疼。

那么我该如何让 apache 只从磁盘流式传输文件?而且它为什么要将文件加载到 RAM 中?磁盘 i/o 比网络快得多,因此将文件从磁盘缓存到内存是没有意义的。

我尝试过:

  • 从 mpm_prefetch 切换到 mpm_event。
  • EnableSendfile On,似乎什么也没做。
  • mod_xsendfile 具有XSendFile On
  • 寻找其他解决方案,包括
    • 这个不适用,因为单个 worker 使用所有的 RAM 来加载单个大文件到 RAM 中
    • 这个不适用,因为即使我运行 PHP,问题也出在对磁盘上的静态文件的获取请求上,而不是 PHP。也无法安装更多 RAM。
    • 这个,我甚至不知道他们到底在说什么配置文件。同样,这不是 PHP 问题。
    • 更多关于 PHP 大型上传和 PUT 请求以及其他 PHP 内容的讨论。

如果可能的话,我希望避免对 nginx 托管文件进行反向代理,因为那只会增加一切的复杂性。

我的一个虚拟主机存在此问题:

<IfModule mod_ssl.c>
    <VirtualHost *:443>
        ServerName host.tld
        ServerAdmin [email protected]

        DocumentRoot /var/www/web
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        # Generate more pleasing and modern looking listing
        IndexOptions FancyIndexing IconsAreLinks FoldersFirst

        EnableSendfile On
        EnableMMAP     Off
        <IfModule mod_xsendfile.c>
            <Directory "/var/www/web">
                XSendFile On
                XSendFilePath /var/www/web
            </Directory>
        </IfModule>

        <IfModule mod_rewrite.c>
            RewriteEngine on
            RewriteRule ^/\.well-known/carddav /nextcloud/remote.php/dav [R=301,L]
            RewriteRule ^/\.well-known/caldav /nextcloud/remote.php/dav [R=301,L]
            RewriteRule ^/\.well-known/webfinger /nextcloud/index.php/.well-known/webfinger [R=301,L]
            RewriteRule ^/\.well-known/nodeinfo /nextcloud/index.php/.well-known/nodeinfo [R=301,L]

            RewriteRule ^/ocm-provider/?$ index.php [QSA,L]
        </IfModule>

        <IfModule mod_headers.c>
            # disallow embedding of non https
            Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains"
            # Prevents browsers from interpreting text files as javascript
            Header onsuccess unset X-Content-Type-Options
            Header always set X-Content-Type-Options "nosniff"
            # enable browser side cross site script filter
            Header onsuccess unset X-XSS-Protection
            Header always set X-XSS-Protection "1; mode=block"
            # prevent search engines from indexing the site
            Header onsuccess unset X-Robots-Tag
            Header always set X-Robots-Tag "noindex, nofollow"
            # prevent embedding in other sites
            Header onsuccess unset X-Frame-Options
            Header always set X-Frame-Options "SAMEORIGIN"
            Header onsuccess unset X-Permitted-Cross-Domain-Policies
            Header always set X-Permitted-Cross-Domain-Policies "none"
            # prevent browser from sending referrer data when clicking links
            Header onsuccess unset Referrer-Policy
            # Header always set Referrer-Policy "no-referrer"
            Header always set Referrer-Policy "same-origin"
        </IfModule>

        # Private, password protected directory
        <Location "/private">
            # authentication
            AuthType                basic
            AuthName                "My Server"

            # Cache credentials with socache
            AuthBasicProvider       socache dbd

            # also needed for caching: tell cache to cache dbd lookups
            AuthnCacheProvideFor    dbd

            AuthDBDUserPWQuery      "SELECT password FROM authn WHERE user = %s"

            # block all non users.
            Require                 valid-user
        </Location>

        <Location /nextcloud/>
            Require all granted
            AllowOverride All
            Options FollowSymLinks MultiViews

            <IfModule mod_dav.c>
                Dav off
            </IfModule>

            # Disable Basic auth for this
            Satisfy Any
        </Location>

        # SSL settings
        SSLEngine on
        SSLCertificateFile      /etc/letsencrypt/live/host.tld/cert.pem
        SSLCertificateChainFile /etc/letsencrypt/live/host.tld/fullchain.pem
        SSLCertificateKeyFile   /etc/letsencrypt/live/host.tld/privkey.pem
        #Include /etc/letsencrypt/options-ssl-apache.conf

        # Add vhost name to log entries:
        LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"" vhost_combined
        LogFormat "%v %h %l %u %t \"%r\" %>s %b" vhost_common
    </VirtualHost>
</IfModule>

# vim: syntax=apache ts=4 sw=4 sts=4 sr et

我启用的模块:

access_compat.load  authn_core.load authz_core.load  autoindex.load  dir.conf     headers.load    mpm_event.load    proxy.load      reqtimeout.conf  security3.load     socache_shmcb.load  status.load
alias.conf     authn_dbd.load   authz_host.load  dbd.load   dir.load     mime.conf       negotiation.conf   proxy_fcgi.load      reqtimeout.load  setenvif.conf     ssl.conf        unique_id.load
alias.load     authn_file.load  authz_user.load  deflate.conf   env.load     mime.load       negotiation.load   proxy_http.load      rewrite.load     setenvif.load     ssl.load        xsendfile.load
auth_basic.load     authn_socache.load  autoindex.conf  deflate.load    filter.load  mpm_event.conf  proxy.conf proxy_wstunnel.load  security3.conf   socache_memcache.load  status.conf

mpm_event.conf:

<IfModule mpm_event_module>
    StartServers             2
    MinSpareThreads      25
    MaxSpareThreads      75
    ThreadLimit          64
    ThreadsPerChild      25
    MaxRequestWorkers     150
    MaxConnectionsPerChild   0
</IfModule>

apachectl-V:

Server built:   2024-07-17T18:57:26
Server's Module Magic Number: 20120211:126
Server loaded:  APR 1.7.0, APR-UTIL 1.6.1
Compiled using: APR 1.7.0, APR-UTIL 1.6.1
Architecture:   64-bit
Server MPM:     event
  threaded:     yes (fixed thread count)
    forked:     yes (variable process count)
Server compiled with....
 -D APR_HAS_SENDFILE
 -D APR_HAS_MMAP
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D APR_USE_PROC_PTHREAD_SERIALIZE
 -D APR_USE_PTHREAD_SERIALIZE
 -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
 -D APR_HAS_OTHER_CHILD
 -D AP_HAVE_RELIABLE_PIPED_LOGS
 -D DYNAMIC_MODULE_LIMIT=256
 -D HTTPD_ROOT="/etc/apache2"
 -D SUEXEC_BIN="/usr/lib/apache2/suexec"
 -D DEFAULT_PIDLOG="/var/run/apache2.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="mime.types"
 -D SERVER_CONFIG_FILE="apache2.conf"

使用 curl 下载 2GB 静态文件时查看 /proc/meminfo。文本是在开始下载后大约 10 秒内 ssh 连接断开时显示的。到那时 curl 还没有收到一个字节。

MemTotal:        3880848 kB
MemFree:          190000 kB
MemAvailable:     479864 kB
Buffers:           52840 kB
Cached:           458780 kB
SwapCached:        63000 kB
Active:           502232 kB
Inactive:        2665432 kB
Active(anon):     318696 kB
Inactive(anon):  2479580 kB
Active(file):     183536 kB
Inactive(file):   185852 kB
Unevictable:       26756 kB
Mlocked:           26756 kB
SwapTotal:       4095996 kB
SwapFree:        2418916 kB
Dirty:                52 kB
Writeback:           192 kB
AnonPages:       2626292 kB
Mapped:           172496 kB
Shmem:            134752 kB
KReclaimable:     292096 kB
Slab:             411324 kB
SReclaimable:     292096 kB
SUnreclaim:       119228 kB
KernelStack:        8768 kB
PageTables:        22876 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:     6036420 kB
Committed_AS:    8174592 kB
VmallocTotal:   133143592960 kB
VmallocUsed:       27632 kB
VmallocChunk:          0 kB
Percpu:             3216 kB
AnonHugePages:         0 kB
ShmemHugePages:        0 kB
ShmemPmdMapped:        0 kB
FileHugePages:         0 kB
FilePmdMapped:         0 kB
CmaTotal:          65536 kB
CmaFree:               0 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
Hugetlb:               0 kB
apache-2.4
  • 1 个回答
  • 93 Views
Martin Hope
SuperAl
Asked: 2025-01-01 07:37:13 +0800 CST

Linux 上的哪个 PHP 配置文件是‘真正的’?

  • 5

在将 Apache/PHP/MySQL 上的一些网站从 Windows Server 主机迁移到 Linux 主机的过程中,我将它们还原到文件系统,配置了虚拟主机和所有管道,连接到 MySQL 数据库,然后登录其中一个。过了一会儿,它抛出了此错误消息:

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 1228800 bytes)

我认为这应该是小菜一碟,于是我将其改为memory_limit256M /etc/php.ini,然后关闭 httpd 然后再启动。但没那么快!PHPInfo 仍然显示旧值:

memory_limit    128M    128M

应用程序仍然抛出与上述完全相同的错误。我仔细检查了 PHPInfo 是否也显示与我编辑的文件相同的文件:

Configuration File (php.ini) Path   /etc
Loaded Configuration File   /etc/php.ini
Scan this dir for additional .ini files     /etc/php.d 

搜索并在 3x 文件中找到了它:,和。我相信 Linux 现在默认运行,所以我/etc将所有 3x 中的值更改为 256、257 和 258M,只是为了能够分辨,但停止并重新启动后 PHPInfo 仍然显示 128M。memory_limitphp.iniphp.ini.rpmnewphp-fpm.d/www.confphp-fpmhttpd

我甚至进入了实际的网络应用程序并改变了它们的内存限制定义但无济于事。

内存限制隐藏在哪里?

apache-2.4
  • 1 个回答
  • 23 Views
Martin Hope
Matthias Ronge
Asked: 2024-12-06 00:30:36 +0800 CST

如何阻止 Apache 在 HTML 标头破坏之前返回错误行

  • 6

我使用一个可以在 Apache 中发布文件的简单站点:

文件:/etc/apache2/sites-enabled/contents.conf
<Directory "/mnt/data/contents/">

        Options FollowSymLinks

        Require all granted

        <IfModule mod_expires.c>
                ExpiresActive on
                ExpiresDefault "access plus 7 days"
        </IfModule>
</Directory>

这些文件是简单的 XML,示例以以下几行开始:

<mets:mets xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:xlink="http://www.w3.org/1999/xlink"
           xmlns:kitodo="http://meta.kitodo.org/v1/"

当我在本地下载文件时,wget抱怨没有标题:

user@myhostname:~$ wget http://myhostname/contents/example/example.xml
--2024-12-05 16:14:59--  http://myhostname/contents/example/example.xml
Resolving myhostname (myhostname)... 127.0.1.1
Connecting to myhostname (myhostname)|127.0.1.1|:80... connected.
HTTP request sent, awaiting response... 200 No headers, assuming HTTP/0.9
Length: unspecified
Saving to: ‘example.xml’

example.xml                                        [      <=>                                                                                                                                ]  12,66K  --.-KB/s    in 4,8s

2024-12-05 16:15:04 (2,66 KB/s) - ‘example.xml’ saved [12966]

下载的文件开始如下:

 12:25:45 GMT
Accept-Ranges: bytes
Content-Length: 12563
Cache-Control: max-age=0
Expires: Thu, 05 Dec 2024 09:45:44 GMT
Vary: Accept-Encoding
X-Content-Type-Options: nosniff
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: application/xml; charset=utf-8

<mets:mets xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:xlink="http://www.w3.org/1999/xlink"
           xmlns:kitodo="http://meta.kitodo.org/v1/"

显然,第一行不属于那里,并且阻止正确识别 HTTP 标头。该行来自哪里?我该如何关闭它?我在其他系统上没有遇到过类似情况。

服务器版本:Apache/2.4.41(Ubuntu)

已加载的模块:
core_module(静态)
so_module(静态)
watchdog_module(静态)
http_module(静态)
log_config_module(静态
) logio_module(静态)
version_module(静态)
unixd_module(静态
) access_compat_module(共享)
alias_module(共享)
auth_basic_module
(共享) authn_core_module(共享)
authn_file_module(共享)
authnz_ldap_module
(共享)
authz_core_module(共享) authz_host_module
(共享) authz_user_module(共享)
autoindex_module(共享)
dav_module(共享)
dav_fs_module(共享)
deflate_module(共享)
dir_module(共享)
env_module(共享)
expires_module(共享)
filter_module(共享)
headers_module(共享)
jk_module(共享)
ldap_module(共享)
mime_module(共享)
mpm_prefork_module(共享)
negotiation_module(共享)
php7_module(共享)
reqtimeout_module(共享)
rewrite_module(共享)
setenvif_module(共享)
socache_shmcb_module(共享)
ssl_module(共享)
status_module(共享)

文件:(/etc/apache2/sites-enabled/000-default.conf评论已删除)
<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/typo3/public

        <Directory /var/www/typo3/public/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                Allow from all
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        JkMount /kitodo ajp13_worker
        JkMount /kitodo/* ajp13_worker
        <Location /kitodo>
                Order allow,deny
                Allow from all
        </Location>
</VirtualHost>
文件:(/etc/apache2/sites-enabled/default-ssl.conf评论已删除)
<IfModule mod_ssl.c>
        <VirtualHost _default_:443>
                ServerAdmin webmaster@localhost

                DocumentRoot /var/www/html

                ErrorLog ${APACHE_LOG_DIR}/error.log
                CustomLog ${APACHE_LOG_DIR}/access.log combined

                SSLEngine on
                SSLCertificateFile      /etc/ssl/certs/ssl-cert-snakeoil.pem
                SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key

                <FilesMatch "\.(cgi|shtml|phtml|php)$">
                                SSLOptions +StdEnvVars
                </FilesMatch>
                <Directory /usr/lib/cgi-bin>
                                SSLOptions +StdEnvVars
                </Directory>
        </VirtualHost>
</IfModule>

编辑:输出curl -i:

user@myhostname:~# curl -i http://myhostname/contents/example/example.xml
curl: (1) Received HTTP/0.9 when not allowed

输出wget -O - -o /dev/null --save-headers

 09:41:43 GMT
Accept-Ranges: bytes
Content-Length: 10971
Cache-Control: max-age=0
Expires: Mon, 09 Dec 2024 08:22:33 GMT
Vary: Accept-Encoding
X-Content-Type-Options: nosniff
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: application/xml; charset=utf-8

(...)
ataTable:11:inputText&quot;,onco:function(xhr,status,args,data){preserveMetadata(); updateTitleMetadata();;}});" /><s

(...)代表 XML 文件内容。我还看到末尾有一些不应该属于那里的内容。我认识到这些内容是通过 JkMount 包含的 Web 应用程序的一部分。最后一行的内容也因每次请求而异。

输出tcpdump -vv -i any -s 0 'tcp port http'(我希望我得到了正确的行,因为同时有人在服务器上工作):

09:15:05.940645 IP (tos 0x0, ttl 64, id 26047, offset 0, flags [DF], proto TCP (6), length 60)
    localhost.60850 > myhostname.http: Flags [S], cksum 0xff30 (incorrect -> 0x75f8), seq 4023966924, win 65495, options [mss 65495,sackOK,TS val 2467400527 ecr 0,nop,wscale 7], length 0
09:15:05.940660 IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto TCP (6), length 60)
    myhostname.http > localhost.60850: Flags [S.], cksum 0xff30 (incorrect -> 0xbe63), seq 1059986559, ack 4023966925, win 65483, options [mss 65495,sackOK,TS val 1084365632 ecr 2467400527,nop,wscale 7], length 0
09:15:05.940673 IP (tos 0x0, ttl 64, id 26048, offset 0, flags [DF], proto TCP (6), length 52)
    localhost.60850 > myhostname.http: Flags [.], cksum 0xff28 (incorrect -> 0xe51f), seq 1, ack 1, win 512, options [nop,nop,TS val 2467400527 ecr 1084365632], length 0
09:15:05.940703 IP (tos 0x0, ttl 64, id 26049, offset 0, flags [DF], proto TCP (6), length 241)
    localhost.60850 > myhostname.http: Flags [P.], cksum 0xffe5 (incorrect -> 0x771f), seq 1:190, ack 1, win 512, options [nop,nop,TS val 2467400527 ecr 1084365632], length 189: HTTP, length: 189
        GET /contents/example/example.xml HTTP/1.1
        User-Agent: Wget/1.20.3 (linux-gnu)
        Accept: */*
        Accept-Encoding: identity
        Host: myhostname
        Connection: Keep-Alive

09:15:05.940721 IP (tos 0x0, ttl 64, id 2993, offset 0, flags [DF], proto TCP (6), length 52)
    myhostname.http > localhost.60850: Flags [.], cksum 0xff28 (incorrect -> 0xe463), seq 1, ack 190, win 511, options [nop,nop,TS val 1084365632 ecr 2467400527], length 0
09:15:05.946161 IP (tos 0x0, ttl 64, id 2994, offset 0, flags [DF], proto TCP (6), length 11426)
    myhostname.http > localhost.60850: Flags [P.], cksum 0x2b97 (incorrect -> 0xe10f), seq 1:11375, ack 190, win 512, options [nop,nop,TS val 1084365637 ecr 2467400527], length 11374: HTTP
09:15:05.946180 IP (tos 0x0, ttl 64, id 26050, offset 0, flags [DF], proto TCP (6), length 52)
    localhost.60850 > myhostname.http: Flags [.], cksum 0xff28 (incorrect -> 0xb81b), seq 190, ack 11375, win 463, options [nop,nop,TS val 2467400532 ecr 1084365637], length 0
09:15:10.951973 IP (tos 0x0, ttl 64, id 2995, offset 0, flags [DF], proto TCP (6), length 52)
    myhostname.http > localhost.60850: Flags [F.], cksum 0xff28 (incorrect -> 0xa45b), seq 11375, ack 190, win 512, options [nop,nop,TS val 1084370643 ecr 2467400532], length 0
09:15:10.952765 IP (tos 0x0, ttl 64, id 26051, offset 0, flags [DF], proto TCP (6), length 52)
    localhost.60850 > myhostname.http: Flags [F.], cksum 0xff28 (incorrect -> 0x90cb), seq 190, ack 11376, win 512, options [nop,nop,TS val 2467405539 ecr 1084370643], length 0
09:15:10.952792 IP (tos 0x0, ttl 64, id 2996, offset 0, flags [DF], proto TCP (6), length 52)
    myhostname.http > localhost.60850: Flags [.], cksum 0xff28 (incorrect -> 0x90ca), seq 11376, ack 191, win 512, options [nop,nop,TS val 1084370644 ecr 2467405539], length 0

您可以看到最后三个条目恰好在 5 秒后出现,这是底部不相关的内容。


重要补充发现:

  • Web 文件夹已完全清空,没有 .htaccess 文件可以播放。

  • 如果通过压缩查询 (Accept-Encoding gzip) 检索 XML 文件,则不会发生此行为

  • 如果我从“conf-enabled”中删除“security.conf”,我会得到略有不同(但仍然是错误的)的第一行输出:st-Modified: Thu, 28 Nov 2024 09:41:43 GMT[sic!]

  • 仅当通过指向 CIFS 挂载点的 Web 文件夹中的符号链接下载 XML 文件时才会发生此行为,而当 XML 文件位于文件夹中时则不会发生此行为

apache-2.4
  • 1 个回答
  • 94 Views
Martin Hope
François Pellissier
Asked: 2024-11-24 02:17:51 +0800 CST

传入的网络流量转到其他 Apache 虚拟主机

  • 5

我尝试在 Raspberry 上设置本地 Web 服务器。我启动并运行了 LAMP 安装,当我直接在服务器上打开页面时,主机和虚拟主机都正常,但网络上其他设备的所有传入流量都会转到“other_vhosts_access.log”。

我做了什么

在我的计算机上,/etc/hosts 文件包含将www.webfantasy.test重定向到服务器的行:

192.168.1.78 www.webfantasy.test

在服务器上,/etc/hosts 文件包含将www.webfantasy.test重定向到 localhost 的行(需要,因为我没有添加 vhost,所以没有加载):

127.0.1.1 www.webfantasy.test

已使用命令“a2dissite”从 sites-enabled 中删除 000-default.conf,并且已重新加载 apache 服务。

特定域的vhost文件激活:

<VirtualHost www.webfantasy.test:80>
    ServerName www.webfantasy.test
    ServerAlias www.webfantasy.test

    DocumentRoot /var/www/webfantasy
    DirectoryIndex index.php

    LogLevel warn
    ErrorLog ${APACHE_LOG_DIR}/webfantasy_error.log
    CustomLog ${APACHE_LOG_DIR}/webfantasy_access.log combined
</VirtualHost>
apache2ctl -t -D DUMP_VHOSTS
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
VirtualHost configuration:
127.0.1.1:80           www.webfantasy.test (/etc/apache2/sites-enabled/webfantasy.conf:1)

我得到了什么

  • 从服务器来看,www.webfantasy.test使用正确的页面(/var/www/webfantasy/index.php)回答,并记录在 webfantasy_access.log 文件中
  • 在我的计算机上,www.webfantasy.test使用默认的 Debian/Apache 页面 (var/www/html/index.html) 进行响应,并记录在 other_vhosts_access.log 文件中

有人知道我应该修改什么才能正常工作吗?

apache-2.4
  • 1 个回答
  • 28 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve