简体   繁体   English

Django + apache&mod_wsgi:更改后必须重启apache

[英]Django + apache & mod_wsgi: having to restart apache after changes

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. 除非我重新启动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. 在某些情况下,更改会在不重新启动Web服务器的情况下生效,但在让我们说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. 到现在为止我只是重新加载每次apache,因为我在这里有我的开发服务器,但是HELL过了一段时间后非常讨厌。 How can I avoid this? 我怎么能避免这个?

I can't work with the development server as I need an environment that is as close as possible as the production one. 我无法使用开发服务器,因为我需要一个尽可能接近生产环境的环境。

Thanks 谢谢

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.wsgi and the daemon will know to restart the app. 这样您就不需要重启apache了,只需touch my_handler.wsgi ,守护进程就会知道重启应用程序。 The apache httpd will not be only yours (in production) so it is fair not to restart it on every update. apache httpd不仅仅是你的(在生产中)所以不公平地重新启动每次更新都是公平的。

No changes require you to RESTART. 没有任何更改需要您重新启动。 You simply need to reload using "sudo /etc/init.d/apache2 reload". 您只需使用“sudo /etc/init.d/apache2 reload”重新加载。 Which I have aliased in my bashrc to 'a2reload'. 我把bashrc中的别名变为'a2reload'。

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

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'rowserver'(它会自动重新启动更改),除非您需要一些特定于Apache的功能(例如多线程)。

Note also that changes in templates do not require the restart of the web server. 另请注意,模板中的更改不需要重新启动Web服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM