Python Django + apache 和 mod_wsgi:更改后必须重新启动 apache

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4206000/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 14:45:47  来源:igfitidea点击:

Django + apache & mod_wsgi: having to restart apache after changes

pythondjangoapachemod-wsgidjango-wsgi

提问by nemesisdesign

I configured my development server this way:

我以这种方式配置了我的开发服务器:

Ubuntu, Apache, mod_wsgi, Python 2.6

Ubuntu、Apache、mod_wsgi、Python 2.6

I work on the server from another computer connected to it.

我从连接到它的另一台计算机在服务器上工作。

Most of the times the changes don't affect the application unless I restart Apache. In some cases the changes take effect without restarting the webserver, but after let's say 3 or 4 page loads the application might behave like it used to behave previous to the changes.

大多数情况下,除非我重新启动 Apache,否则更改不会影响应用程序。在某些情况下,更改无需重新启动网络服务器即可生效,但假设加载 3 或 4 个页面后,应用程序的行为可能与更改前的行为相同。

Until now I just reloaded everytime apache as I have the development server here with me, but HELL after a while got so annoying. How can I avoid this?

到现在为止,我每次都重新加载 apache,因为我在这里有开发服务器,但是过了一段时间就变得很烦人了。我怎样才能避免这种情况?

I can't work with the development server as I need an environment that is as close as possible as the production one.

我无法使用开发服务器,因为我需要一个与生产服务器尽可能接近的环境。

Thanks

谢谢

采纳答案by vonPetrushev

My suggestion is that you run the application in daemon mode. This way you won't be required to restart apache, just touch my_handler.wsgiand the daemon will know to restart the app. The apache httpd will not be only yours (in production) so it is fair not to restart it on every update.

我的建议是您在守护进程模式下运行应用程序。这样你就不需要重新启动 apache,只要touch my_handler.wsgi守护进程知道重新启动应用程序。apache httpd 不仅是你的(在生产中),所以每次更新时不要重新启动它是公平的。

回答by Don

Apache loads Django environment when starting and keep running it even when source is changed.

Apache 在启动时加载 Django 环境,并在源代码更改时继续运行它。

I suggest you to use Django 'runserver' (which automatically restarts on changes) in heavy development sessions, unless you need some Apache-specific features (such as multi-thread).

我建议您在繁重的开发会话中使用 Django 'runserver'(它会在更改时自动重新启动),除非您需要一些特定于 Apache 的功能(例如多线程)。

Note also that changes in templates do not require the restart of the web server.

另请注意,模板中的更改不需要重新启动 Web 服务器。

回答by RoosterJuice

No changes require you to RESTART.You simply need to reload using "sudo /etc/init.d/apache2 reload". Which I have aliased in my bashrc to 'a2reload'.

没有任何更改需要您重新启动。您只需要使用“sudo /etc/init.d/apache2 reload”重新加载。我在 bashrc 中将其别名为“a2reload”。

function a2reload (){
sudo /etc/init.d/apache2 reload
}