English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
So far, in our instance, we have been using Django to develop web servers. But this server is only for testing and not suitable for production environment. Once the program is released and put into production, a real server like Apache, Nginx is needed, and we will discuss the configuration of Apache in this section.
The service of Django application is completed through Apache using mod_wsgi. Therefore, the first thing to do is to make sure you have installed Apache and mod_wsgi. Remember, when we create our project, the project structure should look like the following as shown. -
# Filename : example.py # Copyright : 2020 By w3codebox # Author by : www.oldtoolbag.com # Date : 2020-08-08 myproject/ manage.py myproject/ __init__.py settings.py urls.py wsgi.py
wsgi.py file is a consideration of the relationship between Django and Apache and handling.
For example, we want to share the project (myproject) in Apache. We just need to set Apache to access this folder. Assume we put the myproject folder in "/var/www/html". At this stage, accessing the project will be via http://127.0.0.1/myproject to complete. This will cause Apache to list the folder as shown in the following snapshot.
It can be seen that Apache does not need to handle Django. For the things that need to be handled, they need to be configured in Apache's httpd.conf. Therefore, open httpd.conf and add the following lines -
# Filename : example.py # Copyright : 2020 By w3codebox # Author by : www.oldtoolbag.com # Date : 2020-08-08 WSGIScriptAlias / /var/www/html/myproject/myproject/wsgi.py WSGIPythonPath /var/www/html/myproject/ <Directory /var/www/html/myproject/> <Files wsgi.py> Order deny,allow Allow from all </Files> </Directory>
If you can access the login page: http://127.0.0.1/myapp/connection, you will see the following page -