Apache:To Config The Vhost of Django Project

时间:2022-01-31 14:46:32

It is not a good idea to use dev server in Production Environment.

Apache or Nginx are good choice.Both of them are of great used as the web server.

I'm trying to deploy in apache.

The File Structre:

If you've read djangoproject's documentation,you will find that my project's file structure is a bit different from what the documentation show(via)

Both are ok.

Apache:To Config The Vhost of Django Project

Imagine that you have the apache installed.And now ,lets do it 1 by 1.

Step 1:Edit The httpd.conf

/path/to/the/apache/conf/thhpd.conf

Add a new line just at the end of the file.It seems to be looked like this:

Apache:To Config The Vhost of Django Project

The windows WAMP version:

Apache:To Config The Vhost of Django Project

You need do nothing but just add this line in httpd.conf.I suggest you to do like that,because to config your apache_django project in a included file will not break the  protect the integrity of httpd.conf.

Step 2:Add mod_wsgi in to the modules path of apache:

While the Python gets a x86 and x64 version, and it is the same with the mod_wsgi

First, download the right version of mod_wsgi.For example,I have Python2.7.x.amd64 and Apache 2.4.x installed in my pc(x64).So, I need to use (via)

Apache:To Config The Vhost of Django Project

Uzip the package and you will get a mod_wsgi.so.

Put it in the apache modules

Apache:To Config The Vhost of Django Project

Step 3:Edit the apache_django.conf and apache_django.wsgi

Apache_django.conf

Ps.in this config file,I load the mod_wsgi module,config the vietual python env

Listen the 8000 port which is used in my django project and in the <VirtualHost 127.0.0.1:8000> ….. </VirtualHost> I config something of my project.

Apache:To Config The Vhost of Django Project

Apache_django.wsgi

In this file ,I add the project into the python path so that django driver can get the application

Apache:To Config The Vhost of Django Project

Step 4:cp the project files in to the www:

Seems like that:

Apache:To Config The Vhost of Django Project

Let's check into it

Apache:To Config The Vhost of Django Project

After all above,restart apache server.type http://127.0.0.1:8000

Apache:To Config The Vhost of Django Project

Shit,what's happened?

Check in the log path No Error found

Apache:To Config The Vhost of Django Project

Check httpd.conf:

Apache:To Config The Vhost of Django Project

Add this:

Apache:To Config The Vhost of Django Project

Check www root:seems ok

Apache:To Config The Vhost of Django Project

OK,restart apache:

Near to success!

Apache:To Config The Vhost of Django Project

Check in the error log:

Apache:To Config The Vhost of Django Project

….No module…….orz….

Apache_django.wsgi line 3

Apache:To Config The Vhost of Django Project

Maybe there's something wrong with my WSGIPythonPath

Apache:To Config The Vhost of Django Project

Let's have a look at where the virtual env's site-packages are:

Apache:To Config The Vhost of Django Project

……………………………………..orz…

Change it!

Apache:To Config The Vhost of Django Project

Restart apache service! Apache:To Config The Vhost of Django Project

Apache:To Config The Vhost of Django Project

Apache:To Config The Vhost of Django Project

I give up…

Tomorrow will be ok

Time to sleep…