我已为 sites-enabled 目录中的某个网站编辑了变量 AllowOverride 。如何在不重新启动apache的情况下重新加载新配置?有可能吗?
答案 0 :(得分:146)
应该可以使用命令
sudo /etc/init.d/apache2 reload
希望有所帮助
答案 1 :(得分:98)
其他方式是:
sudo service apache2 reload
答案 2 :(得分:24)
答案 3 :(得分:6)
更新了Apache 2.4,非systemd(例如,CentOS 6.x,Amazon Linux AMI)和systemd(例如,CentOS 7.x):
有两种方法可以让apache进程重新加载配置,具体取决于你想要对当前线程做什么,或者建议在空闲时退出,或者直接终止它们。
请注意,Apache建议使用bash-3.2$ pry
[1] pry(main)> require 'rack' # rack-2.0.3 installed
=> true
[2] pry(main)> Rack::Session
=> Rack::Session
[3] pry(main)> Rack::Session.constants
=> [:Cookie, :Pool, :Memcache]
[4] pry(main)> Rack::Session.const_defined?(:Memcache)
=> true
[5] pry(main)> Rack::Session.const_get(:Memcache)
LoadError: cannot load such file -- memcache
from /Users/user/.rbenv/versions/2.3.4/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
[6] pry(main)> wtf????
Exception: LoadError: cannot load such file -- memcache
--
0: /Users/user/.rbenv/versions/2.3.4/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
1: /Users/user/.rbenv/versions/2.3.4/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
2: /Users/user/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/rack-2.0.3/lib/rack/session/memcache.rb:4:in `<top (required)>'
3: /Users/user/.rbenv/versions/2.3.4/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
4: /Users/user/.rbenv/versions/2.3.4/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
5: (pry):4:in `const_get'
6: (pry):4:in `__pry__'
7: /Users/user/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/pry-0.10.4/lib/pry/pry_instance.rb:355:in `eval'
8: /Users/user/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/pry-0.10.4/lib/pry/pry_instance.rb:355:in `evaluate_ruby'
9: /Users/user/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/pry-0.10.4/lib/pry/pry_instance.rb:323:in `handle_line'
10: /Users/user/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/pry-0.10.4/lib/pry/pry_instance.rb:243:in `block (2 levels) in eval'
11: /Users/user/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/pry-0.10.4/lib/pry/pry_instance.rb:242:in `catch'
12: /Users/user/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/pry-0.10.4/lib/pry/pry_instance.rb:242:in `block in eval'
13: /Users/user/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/pry-0.10.4/lib/pry/pry_instance.rb:241:in `catch'
14: /Users/user/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/pry-0.10.4/lib/pry/pry_instance.rb:241:in `eval'
15: /Users/user/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/pry-0.10.4/lib/pry/repl.rb:77:in `block in repl'
16: /Users/user/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/pry-0.10.4/lib/pry/repl.rb:67:in `loop'
17: /Users/user/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/pry-0.10.4/lib/pry/repl.rb:67:in `repl'
18: /Users/user/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/pry-0.10.4/lib/pry/repl.rb:38:in `block in start'
19: /Users/user/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/pry-0.10.4/lib/pry/input_lock.rb:61:in `__with_ownership'
20: /Users/user/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/pry-0.10.4/lib/pry/input_lock.rb:79:in `with_ownership'
21: /Users/user/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/pry-0.10.4/lib/pry/repl.rb:38:in `start'
22: /Users/user/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/pry-0.10.4/lib/pry/repl.rb:15:in `start'
23: /Users/user/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/pry-0.10.4/lib/pry/pry_class.rb:169:in `start'
24: /Users/user/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/pry-byebug-3.4.2/lib/pry-byebug/pry_ext.rb:11:in `start_with_pry_byebug'
25: /Users/user/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/pry-0.10.4/lib/pry/cli.rb:219:in `block in <top (required)>'
26: /Users/user/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/pry-0.10.4/lib/pry/cli.rb:83:in `block in parse_options'
27: /Users/user/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/pry-0.10.4/lib/pry/cli.rb:83:in `each'
28: /Users/user/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/pry-0.10.4/lib/pry/cli.rb:83:in `parse_options'
29: /Users/user/.rbenv/versions/2.3.4/lib/ruby/gems/2.3.0/gems/pry-0.10.4/bin/pry:16:in `<top (required)>'
30: /Users/user/.rbenv/versions/2.3.4/bin/pry:22:in `load'
31: /Users/user/.rbenv/versions/2.3.4/bin/pry:22:in `<main>'
[7] pry(main)> Rack::Session.method(:constants).source_location
=> nil
[8] pry(main)> Rack::Session.method(:const_get).source_location
=> nil
[9] pry(main)> Rack::Session.method(:const_missing).source_location
=> nil
[10] pry(main)> Rack::Session.method(:const_defined?).source_location
=> nil
作为命令,对于systemd,命令将替换为apachectl -k
httpd -k
或apachectl -k graceful
Apache会建议其线程在空闲时退出,然后apache重新加载配置(它不会自行退出),这意味着统计信息不会重置。
httpd -k graceful
或apachectl -k restart
这类似于stop,因为该进程会终止其线程,但随后该进程会重新加载配置文件,而不是自杀。
答案 4 :(得分:3)
如果使用Ubuntu服务器,则可以使用systemctl
systemctl reload apache2
答案 5 :(得分:0)
此处的答案较晚,但如果您搜索 /etc/init.d/apache2
以查找 'reload',您会发现如下内容:
do_reload() {
if apache_conftest; then
if ! pidofproc -p $PIDFILE "$DAEMON" > /dev/null 2>&1 ; then
APACHE2_INIT_MESSAGE="Apache2 is not running"
return 2
fi
$APACHE2CTL graceful > /dev/null 2>&1
return $?
else
APACHE2_INIT_MESSAGE="The apache2$DIR_SUFFIX configtest failed. Not doing anything."
return 2
fi
}
基本上,建议使用 init.d、systemctl 等的答案调用的是一个瘦包装器,上面写着:
apachectl graceful
(吞下输出,转发退出代码)这表明@Aruman 的回答也是正确的,前提是您确信配置中没有错误或已经手动运行了 apachctl configtest
。
apache documentation 还提供了用于正常重启 (apachectl -k graceful
) 的相同命令,并为其行为提供了更多颜色。