Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Mac configuration Django 1.7.1 + mod_wsgi 4

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Today, I'm going to configure django on the apache server, which is too bad. After reading a few blogs, it was either a hasty stroke or without a version number, which made me confused. Finally, I read the official documents and figured it out. Here I write a little more detailed summary, which is suitable for rookies who do not quite understand. Because I am. --!

Restate my current version:

Django 1.7.1 + mod_wsgi 4.4.7 (non-daemon) + Apache/2.2.26mac I didn't upgrade the new Yosomite system, so the version number is 10.9.5

I don't need to install apache for you. It looks like mac has already been installed. (if you're wrong, don't shoot me. Skip this step, and we'll talk about configuring apache later)

The first thing mac does is to install xcode. Why install xcode in order to install a tool called Commandline tool?

Where? Xcode-"prefrence- > download, did you see that?

What? Doesn't see it? Then you enter it on the command line.

Xcode-select-install

Will automatically pop up a box for you to install the tool I just mentioned, all right, wait for him to finish the installation!

Step 2: install homebrew

This time for me to write articles is not like the installation method in previous blogs.

Ruby-e "$(curl-fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Use this to download and install directly

Part 3: install mod_wsgi, this time you will use the brew you just installed

Brew install homebrew/apache/mod_wsgi

It can be seen that in order to install only a mod_wsgi, there is no need to investigate his principle. As long as we have successfully installed it, we can use it to complete our own tasks. To put it simply, this thing is used to successfully run a middleware in Apache using a third-party web application written by python after configuring Apache, so it can be regarded as a bridge between application and Apache. It depends on him for post-configuration file paths and everything.

Step 4:

Now that we have everything we need, it's time to go to the configuration file.

Httpd.conf in apache2 this is a very important configuration file for apache. My path is in

/ etc/apache2/httpd.conf

How do I get there? I won't tell you to open Finder and then Command+Shift + G

What should I write? you say that now we have django and Apache on both sides of the bridge, and the rest is to put the bridge between the two, yes, build a bridge!

On the one hand, take advantage of the mod_wsgi just installed, and on the other hand, use our django.

Mod_wsgi first, open the httpd.conf file above, at the end, add how to line first

LoadModule wsgi_module / usr/local/Cellar/mod_wsgi/4.4.7/libexec/mod_wsgi.so

Ohh! It can be interpreted as asking Apache to load the mod_wsgi file that you just downloaded, yes!

As for why?

/ usr/local

What about this path? Your installation is suitable for people to put it there. What can you do? just bring it here!

And then! Add another line

WSGIPythonPath / Library/WebServer/Documents/my2site

You can see the back.

/ Library/WebServer/Documents/my2site

This is when you use startproject to create the root directory, that is, the root directory of the entire site to find out directly affixed to the back, the use of this can be understood as allowing Apache to find your django root directory, how about, the bridge built, right? Yes!

But there is still something missing, the most critical file, wsgi.py, which has been automatically created when the django project is created, we just need to bring it in as above, for example, mine is

WSGIScriptAlias / / Library/WebServer/Documents/my2site/my2site/wsgi.py

It is found here that there is a / what this is in the middle. He is your root directory! That is to say, the home address, like this, my main business is 127.0.0.1. If I change this / to / app, what is my home page? You got it right.

And then I'm going to write a sentence like this.

Allow from allOrder deny,allow

His function is to let Apache read the wsgi.py you just introduced, so they are paired!

Note: because the version of apache is 2.2.26 and less than 2.4, I used these two lines

Allow from allOrder deny,allow

If you are older than version 2.4 of Apache, you need to replace these two lines with one line

Require all granted

OK!

In this way, the bridge will be built.

Take a look at the home page should be displayed, but you will find that many of our static files can not be displayed, this is because django is no longer responsible for associating your static file path, need Apache to configure, how to configure? Thinking that we all introduced the experience of wsgi.py files just now, we also introduced the root directory of static.

It's just that the keywords are different. This time we use Alias

Alias / static/ / Library/WebServer/Documents/my2site/polls/statics_file/

Static is the STATIC_URL in settings. The one behind it is his real catalogue.

Don't forget to give Apache the right to access files!

Allow from allOrder deny,allow

Still pay attention to the Apache version. Yes, they are also a couple.

So let's look back and see if our home page is exactly the same as before.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report