青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

c++實例研究

從0開始

  C++博客 :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
  104 隨筆 :: 0 文章 :: 20 評論 :: 0 Trackbacks

原文http://www.winged.ch/blog/3/

Cherokee and Django

Published: 2009-09-05 22:31
Comments: 2
A friend asked me about how I've set up my web server, and how I've configured Django, Cherokee etc. So I decided to write a short tutorial on how to proceed.

I'm going to assume that you know how to handle a UNIX/Linux-based server, and make sure you're comfortable handling the shell ;)

The article got a bit long, but bare with me, you're gonna learn a thing or two. And if you already know some stuff, you can skip a few sections, I won't send the hangman after ya.

Installing Cherokee, Django, Postgresql

My Server was set up as an ubuntu 9.04 machine. However, a few software components are a bit dated, as they need to look for stability and so on... you know the drill.

So, where was I? Right, Cherokee. You can get a recent Cherokee binary from here. Just add the line to your /etc/apt/sources.list and import the PPA's signing key.

Here's how to go if you're in a hurry*. Be sure to use TWO >'s here... or you're in trouble.

$ echo deb http://ppa.launchpad.net/cherokee-webserver/ppa/ubuntu jaunty main  >> /etc/apt/sources.list
$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys EBA7BD49

Now we're ready to install the webserver.

$ sudo apt-get update
$ sudo apt-get install cherokee

The next step is easy, as Jaunty has a pretty recent version of Postgresql. Note that you can use MySQL as well here, but I'm using Postgresql.

$ sudo apt-get install postgresql

Now we need to create a user for your application, and a database as well. For this, we need to create a new user. Run this to become the postgres user. In the default installation, this is the only way to get into postgresql with admin rights.

$ sudo su - postgres

This following command should put you in an SQL shell, with admin rights:

$ psql

Now create the user to access the database later:

postgres=# CREATE USER my_webapp LOGIN PASSWORD 'mypasswd';

Create the database. Note the encoding and the owner!

postgres=# CREATE DATABASE webapp ENCODING 'utf-8' OWNER my_webapp;

Now your database is ready. Get out of the SQL shell (CTRL-D), and out of postgres's shell too.

Installing django is easy. I started development with the 1.0 branch and I didn't update to 1.1 yet, so I was happy with the django version that's coming with ubuntu:

$ sudo apt-get install python-django

But... you will need something more to get django running with cherokee and Postgresql:

$ sudo apt-get install python-flup python-psycopg2

The deployment

Now.. to get your Django application online, create a new user for your project:

$ sudo useradd -m my_webapp
$ sudo passwd my_webapp

The -m flag tells the useradd tool to automatically create the home directory for you.

Before we continue, you go get your django app and put it in this new user's home directory, configure it to access the right database, run django-admin syncdb or whatever you need to get the installation working. I'll wait here for you.

Back? Good.

Now, there are two ways of setting up Cherokee for your web app. A very easy, but inflexible way (it works, but you don't know why), and a way that requires a little bit more work (If it doesn't work, you'll know why).

The first way would be to use Cherokee's new platform wizard. However, it just creates a standard setup (and names things with just numbers), so I prefer the second way.

Sooo... back to setting up Cherokee. Maybe you've already read about it, but: We're not going to hack config files. Cherokee has a nifty configuration interface that is very easy to use. Here's how:

Configuring Cherokee

$ sudo cherokee-admin

This command starts a web interface and prints out all the information to access it - note how it creates a temporary password for extra security:

Login:
User: admin
One-time Password: VbBr4P2azYE8RJEW

Web Interface:
URL: http://127.0.0.1:9090/

Now point your browser to that URL. Obviously, you need to change the IP address to the address of the actual server. But I don't need to tell you this. Sorry. Cherokee welcome screen

Before we continue, let's take a short digress into the organisation of Cherokee's configuration: As you can see, the menu shows, among a few other things, two entries labeled "Virtual Servers" and "Information Sources". Virtual servers are exactly what you think. You configure domain names, behaviour on URLs, logging here.

Information sources are the way more interesting part, so let's do one of these!

An information source tells Cherokee what to do with an incoming request. After creating one or more information sources, you can then connect virtual servers to them.

As you will see later, you can connect subdirectories to an information source, or a regex (for example, match all requests to a PHP file and give it to an information source that calls the PHP interpreter. But fortunately, we're not going to need this).

Creating an information source

So, what do I need to fill in those fields here? (I didn't need to tell ya to click on "Information Sources", right? You're a coder or an admin, as far as I can see). Setup screen of Cherokee's Information Source

The Nickname is just something for you to remember. The connection... let's write a path to a socket here. I've put /home/my_webapp/xlist.sock in mine.

Now the interpreter is a bit more complicated. Basically, you put your manage.py call here. However, since we're not in development here, we don't want python to run the web server. And since you want to be able to restart the application, and since Cherokee needs something on the other side of the socket... you'll need a bit more than the default options.

And there's a little problem you're probably not forseeing right now: As this line will be run as your normal user instad of cherokee's, the created socket won't be readable by the webserver process. So.. instead of writing a long manage.py line directoy into that field, let's create a small bash scritpt that handles this for us. Put the file in /home/my_webapp/runserver.sh.

#!/bin/bash
PIDFILE=/home/my_webapp/xlist.pid
SOCKFILE=/home/my_webapp/xlist.sock
# kill a possibly running instance
kill $(<$PIDFILE)
rm $SOCKFILE

# run in background so we can chmod the socket afterwards
/home/my_webapp/winged_xlist/manage.py runfcgi \
pidfile=$PIDFILE \
socket=$SOCKFILE \
daemonize=True

# stop if app start fails
if [ $? -ne 0 ]; then
exit $?
fi

# now wait for the socket to be created, then chmod it.
while [ ! -S $SOCKFILE ]
do
sleep 1
done
chmod a+rw $SOCKFILE

Note the script does not care much about protecting the socket file. This isn't actually so bad, as any request a malicious user could put in via the socket file could also be made via webserver. And if you already have malicious local users, you're in trouble anyhow. Maybe not you but the server admin, but.. still, there's trouble. But the point is it doesn't make your application less secure.

Now chmod +x the file and enter it as the interpreter line. I assume you changed the paths to your needs.

The spawning timeout should be fairly enough, but if you're on a shared server, and your codebase is big, you should put a longer timeout there, like 10 seconds or so. This is not gonna make your app slow, as it is only started once if everything's okay.

Execute as User, Execute as Group: Since we don't want the code and passwords and stuff to be readable if the web server gets compromised, put in the user and group that we created before. Here, it is "my_webapp" in both fields.

Note how Cherokee saves the config each time you're done entering a value. To be sure, click somewhere outside of the input fields to be sure it saves your last change. This was it! Your first information source is ready to use!

So let's create a virtual server! I'm so excited! We're almost online!

Virtual Server Setup

Click on that "Add new Virtual Server" button you see in the Virtual Servers menu. Give it a nickname and a document root. Since we're not going to access files directly, I usually put a fake docroot there. But the path must exist, so create some unused directory you can abuse. But DO NOT use a directory that you're actually gonna put stuff in - and make it read-only please. Don't worry about the static content from Django, we'll get to this.

So now you have your new virtual server. Click on it's name!

We don't need to do anything in the Basics tab, so let's skip over to the "Host Match".

Cherokee setup: Host Match

As you can see, I've already added two wildcard matches. You could also add Regexes instead, but normally, the normal wildcard match is sufficient.

The last thing you need now is to configure the behaviour. Behaviours match the request in various ways, then decide what to do with it. As you can see, a few have already been created for you. Delete all but the Default one (you can't anyway :P).

Click on the Default rule's name. You will land on the details page. We can't to do anything more to the rule, so let's go over to the "Handler" tab.

Select the FastCGI option from the dropdown to get the fields shown here.

Cherokee setup: VServer handler

You can leave everything as is, except the "Check file" option. Turn it off. Otherwise, Cherokee will not even pass the request to Django if a file with your URL does not exist. Which would be stupid.

Okay, I lied. There's one other thing you need to do on this page. See the little dropdown labeled "Application Server" at the bottom? Do you recognize the entry you've got there? Yep, it's our information source! Yay! Let's select it!

Now let's see if this works. Select "Graceful restart" in the left panel and click "Save". If everything went fine, you should get a nice green confirmation.

When you point your browser to the server you just created, you should be seeing your web application in all it's glory.

All it's glory? No. All the nice CSS, the pictures, everything.. is missing! HELP!

Configuring Static File Delivery

Okay, I promised you to get back to the static file stuff before, so let's do that. Let's go back to our virtual server and add a rule or two.

What you need here is a bit different depending on how you configured your Django app. I have a /static directory that contains all the CSS and images, so I'll add a new "Directory" rule with the "Web Directory" obviously being "/static". Don't worry about the zapping around after you've entered the directory, Cherokee is just being helpful here.

Switch to the Handler tab now and choose the "Static content" handler. This differs from the "List&Send" insofar as "Static content" doesn't do directory listings.

Enter the path to the static content and save the server's config, again, doing a graceful restart.

If you have more static directories (for example the django admin panel), just repeat as needed.

Congratulations! You are now running your Django application with Cherokee!

* Note: You should NEVER be in a hurry when setting up a server. This is serious business!

Also note: If you have trouble getting this set up, please drop me a comment below, or send me an e-mail. You can reach me at dave AT winged DOT ch.


posted on 2010-06-18 11:15 elprup 閱讀(476) 評論(0)  編輯 收藏 引用 所屬分類: web開發(fā)
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            欧美福利视频在线| 国产伦一区二区三区色一情| 日韩视频专区| 日韩午夜免费| 亚洲一区二区在线看| 亚洲图片欧美午夜| 欧美在线资源| 久久中文在线| 欧美精品大片| 国产精品久久久久久福利一牛影视 | 欧美激情精品久久久六区热门 | 欧美精品一级| 国产在线精品一区二区中文| 欧美午夜精品久久久久免费视 | 欧美h视频在线| 亚洲成色精品| 亚洲精品久久久久久久久久久| 日韩视频一区二区| 午夜视频久久久久久| 久久综合影视| 亚洲国产一二三| 亚洲欧美激情诱惑| 久久夜色精品国产亚洲aⅴ | 欧美在线精品免播放器视频| 免费在线一区二区| 欧美视频在线免费看| 激情成人综合| 亚洲一区精品在线| 欧美h视频在线| 午夜精品www| 欧美精品一区二区蜜臀亚洲| 国产一区二区三区精品欧美日韩一区二区三区| 在线观看欧美日本| 性欧美18~19sex高清播放| 欧美阿v一级看视频| 午夜精品久久| 国产精品日韩欧美一区二区三区| 亚洲狼人综合| 嫩草影视亚洲| 欧美亚洲一级片| 欧美日韩一区二区在线观看视频 | 好吊色欧美一区二区三区四区| aa亚洲婷婷| 欧美1区免费| 午夜精品美女自拍福到在线| 欧美理论大片| 亚洲精品一品区二品区三品区| 久久久蜜桃精品| 亚洲淫片在线视频| 欧美视频精品在线| 夜夜嗨av一区二区三区中文字幕 | 亚洲欧美成人在线| 亚洲国产日韩欧美| 欧美a一区二区| 亚洲国产精品成人综合色在线婷婷| 久久精品亚洲精品| 欧美亚洲免费| 国产综合色产在线精品| 久久国产精品久久久久久| 亚洲午夜极品| 国产精品女人网站| 欧美一级专区免费大片| 亚洲一区二区三区国产| 国产精品欧美激情| 欧美在线观看一二区| 亚洲男人的天堂在线观看| 国产精品一区一区| 久久精品论坛| 久久这里有精品视频| 亚洲激情不卡| 亚洲精品一区二区三区不| 欧美日韩中文字幕日韩欧美| 国产精品嫩草99a| 性欧美超级视频| 欧美一级艳片视频免费观看| 国产主播一区二区三区| 欧美~级网站不卡| 欧美黄色成人网| 亚洲欧美日韩视频一区| 欧美一区二区视频网站| 亚洲激情av在线| 中文av一区特黄| 精品不卡一区二区三区| 最新国产成人av网站网址麻豆| 国产精品99免视看9| 欧美一区亚洲| 欧美aⅴ99久久黑人专区| 亚洲一二三区在线| 久久国产精品久久w女人spa| 亚洲国产中文字幕在线观看| 亚洲精品一区二区在线观看| 国产乱肥老妇国产一区二 | 亚洲主播在线观看| 亚洲成人在线视频网站| 亚洲精品一区二区三区四区高清| 国产欧美日韩精品在线| 亚洲成色精品| 国产日韩欧美综合| 亚洲日本中文字幕区| 国产日韩欧美亚洲| 亚洲电影免费观看高清完整版在线| 欧美视频一区二区三区在线观看| 久久久蜜桃精品| 国产精品久久久久久亚洲毛片| 噜噜噜在线观看免费视频日韩| 欧美日韩视频一区二区| 免费成人高清视频| 国产伦精品一区二区三| 亚洲人体大胆视频| 狠狠色噜噜狠狠色综合久| 99综合在线| 亚洲欧洲一区二区天堂久久 | 欧美日韩精品二区| 裸体一区二区三区| 国产精品私人影院| aa日韩免费精品视频一| 亚洲三级国产| 久久综合久久久久88| 久久国产精品电影| 国产精品毛片大码女人| 亚洲毛片视频| 亚洲精品一区二区三区99| 久久精品国产99国产精品澳门 | 亚洲国产成人精品久久久国产成人一区 | 欧美成人视屏| 久久亚洲精品中文字幕冲田杏梨| 国产精品国产三级国产aⅴ浪潮 | 亚洲福利视频二区| 欧美一级夜夜爽| 先锋影音一区二区三区| 欧美视频精品在线| 亚洲最黄网站| 亚洲在线一区二区三区| 欧美精品久久99| 亚洲福利视频网站| 亚洲激情网址| 男同欧美伦乱| 亚洲成色精品| 亚洲人成在线观看网站高清| 老司机aⅴ在线精品导航| 久久久夜色精品亚洲| 狠狠色伊人亚洲综合成人| 久久久久国产一区二区| 久久视频在线视频| 激情亚洲成人| 另类激情亚洲| 亚洲电影在线免费观看| 99精品99久久久久久宅男| 欧美日韩国产大片| 中文久久精品| 久久精品国产一区二区三| 狠狠入ady亚洲精品| 久久综合九色综合欧美狠狠| 欧美激情在线有限公司| 日韩午夜激情电影| 国产精品扒开腿做爽爽爽软件| 亚洲欧美在线aaa| 久久综合狠狠| av成人免费观看| 国产精品一区视频| 狼人天天伊人久久| 日韩一区二区免费高清| 久久成人一区| 亚洲三级电影在线观看 | 国产精品视频一二| 久久精品一区二区| 亚洲精品国偷自产在线99热| 亚洲尤物视频在线| 一区二区三区亚洲| 欧美日韩一区二区在线观看视频| 午夜精品成人在线| 91久久精品美女| 欧美中文在线观看| 亚洲三级影院| 国产日韩在线播放| 欧美极品在线观看| 欧美影院成人| 亚洲伦理自拍| 美日韩精品视频免费看| 亚洲一区二区三区精品在线观看 | 一区二区三欧美| 狠狠色综合日日| 欧美天堂在线观看| 裸体素人女欧美日韩| 亚洲欧美日韩在线一区| 亚洲精品久久嫩草网站秘色| 久久精选视频| 亚洲一区二区精品在线观看| 在线免费不卡视频| 国产日韩av在线播放| 欧美日韩亚洲综合| 免费观看成人www动漫视频| 午夜精品久久久久久久久久久| 亚洲精品日韩精品| 在线国产日韩| 国产亚洲精品资源在线26u| 欧美日本乱大交xxxxx| 老司机一区二区| 久久久国产亚洲精品| 先锋影音一区二区三区|