apache mod proxy 的问题,它在优雅重启后停止代理请求,但并非总是如此。这种情况似乎只发生在星期日,当 logrotate 触发优雅重启时。
[Sun Sep 9 05:25:06 2012] [notice] SIGUSR1 received. Doing graceful restart
[Sun Sep 9 05:25:06 2012] [notice] Apache/2.2.22 (Ubuntu) Phusion_Passenger/3.0.11 configured -- resuming normal operations
[Sun Sep 9 05:25:06 2012] [error] proxy: ap_get_scoreboard_lb(492) failed in child 26153 for worker proxy:reverse
[Sun Sep 9 05:25:06 2012] [error] proxy: ap_get_scoreboard_lb(486) failed in child 26153 for worker http://api.myservice.org/api
[Sun Sep 9 05:25:06 2012] [error] proxy: ap_get_scoreboard_lb(487) failed in child 26153 for worker http://api.myservice.org/editor/$1
[Sun Sep 9 05:25:06 2012] [error] proxy: ap_get_scoreboard_lb(489) failed in child 26153 for worker http://api.myservice.org/build
[Sun Sep 9 05:25:06 2012] [error] proxy: ap_get_scoreboard_lb(490) failed in child 26153 for worker http://api.myservice.org/help
[Sun Sep 9 05:25:06 2012] [error] proxy: ap_get_scoreboard_lb(491) failed in child 26153 for worker http://api.myservice.org/motd.html
[Sun Sep 9 05:25:06 2012] [error] proxy: ap_get_scoreboard_lb(480) failed in child 26153 for worker http://api.myservice.org/api
[Sun Sep 9 05:25:06 2012] [error] proxy: ap_get_scoreboard_lb(481) failed in child 26153 for worker http://api.myservice.org/editor/$1
[Sun Sep 9 05:25:06 2012] [error] proxy: ap_get_scoreboard_lb(483) failed in child 26153 for worker http://api.myservice.org/build
[Sun Sep 9 05:25:06 2012] [error] proxy: ap_get_scoreboard_lb(484) failed in child 26153 for worker http://api.myservice.org/help
[Sun Sep 9 05:25:06 2012] [error] proxy: ap_get_scoreboard_lb(485) failed in child 26153 for worker http://api.myservice.org/motd.html
[Sun Sep 9 05:25:06 2012] [error] proxy: ap_get_scoreboard_lb(479) failed in child 26153 for worker http://api.myservice.org/motd.html
在这些行之后,日志中充斥着 404,因为请求没有被代理。值得注意的是,目标只是同一 Apache 实例上的另一个虚拟主机,但虚拟主机(http://api.myservice.org) 正在为乘客提供服务 (mod_rails)
我在想,也许存在一些启动问题,乘客工作人员在平稳重启期间尚未准备好?
完全重启后问题解决,一切恢复正常。
//编辑这里是 vhost 配置,谢谢:)
<VirtualHost *:80>
UseCanonicalName Off
LogFormat "%V %h %l %u %t \"%r\" %s %b" vcommon
<Directory /var/www/vhosts>
RewriteEngine on
AllowOverride All
</Directory>
RewriteEngine on
RewriteCond /var/www/vhosts/%{SERVER_NAME} !-d
RewriteCond /var/www/vhosts/%{SERVER_NAME} !-l
RewriteRule ^ http://sitenotfound.myservice.org/ [R=302,L]
VirtualDocumentRoot /var/www/vhosts/%0/current
# Rewrite requests to /assets to map to the /var/file-store/<SERVER_NAME>/
RewriteMap lowercase int:tolower
RewriteCond %{REQUEST_URI} ^/assets/
RewriteRule ^/assets/(.*)$ /var/file-store/${lowercase:%{SERVER_NAME}}/$1
# Map /login to /editor.html as it's far friendlier.
RewriteCond %{REQUEST_URI} ^/login
RewriteRule .* /editor.html [PT]
# Forward some requests to the API
ProxyPass /api http://api.myservice.org/api
ProxyPass /site.json http://api.myservice.org/api/editor/site
ProxyPassMatch ^/editor/(.*)$ http://api.myservice.org/editor/$1
ProxyPassMatch ^/api/(.*) http://api.myservice.org/api/$1
ProxyPass /build http://api.myservice.org/build
ProxyPass /help http://api.myservice.org/help
ProxyPass /motd.html http://api.myservice.org/motd.html
<Proxy *>
Order allow,deny
Allow from all
</Proxy>
# TODO generate slightly more specific Error Documents for 401/403/500's,
# but for now the 404 page is good enough
ErrorDocument 401 /404.html
ErrorDocument 403 /404.html
ErrorDocument 404 /404.html
ErrorDocument 500 /404.html
</VirtualHost>
答案1
我无法回答您关于代理的问题,除了似乎正确的一点,即工作程序无法通过优雅重启正确设置。但我建议,完全不需要重新启动 apache,无论是优雅重启还是其他方式,只是为了轮换日志。您只需要copytruncate
在 logrotate 配置中使用选项;它不会移动文件,需要重新启动才能获取新的文件句柄,而是复制文件的内容并清空旧文件,这样 apache 就可以继续写入相同的文件句柄。