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

c++實(shí)例研究

從0開(kāi)始

  C++博客 :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
  104 隨筆 :: 0 文章 :: 20 評(píng)論 :: 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) 評(píng)論(0)  編輯 收藏 引用 所屬分類: web開(kāi)發(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>
            欧美伦理一区二区| 一区二区三区欧美在线| 99精品欧美| 日韩香蕉视频| 亚洲视频一区| 欧美一区免费视频| 久久蜜桃av一区精品变态类天堂| 久久精品国亚洲| 欧美bbbxxxxx| 亚洲精品综合| 久久成人精品电影| 欧美激情一区三区| 免费观看日韩| 亚洲第一视频| 日韩午夜在线电影| 亚洲一区在线观看视频| 久久综合伊人| 99国产精品久久久久久久成人热| 亚洲一区二区三区精品动漫| 久久免费精品视频| 欧美日韩中文字幕日韩欧美| 好看的亚洲午夜视频在线| 亚洲精品视频在线播放| 欧美一级欧美一级在线播放| 欧美黄色影院| 亚洲女同精品视频| 欧美激情一区二区三区蜜桃视频| 国产日韩av一区二区| 一本色道久久88综合亚洲精品ⅰ| 久久精品国产精品亚洲精品| 亚洲美女在线国产| 久久亚洲欧美| 国产欧美日韩在线播放| 日韩一区二区电影网| 久久一区二区精品| 亚洲综合色丁香婷婷六月图片| 欧美大片免费| 一区二区三区在线观看欧美| 午夜精彩视频在线观看不卡| 亚洲精品日韩综合观看成人91| 久久久久国产精品午夜一区| 国产精品无人区| 亚洲一二三区视频在线观看| 亚洲高清影视| 久久aⅴ国产紧身牛仔裤| 国产精品h在线观看| 日韩亚洲欧美高清| 欧美激情久久久| 久热国产精品| 亚洲国产成人不卡| 欧美mv日韩mv国产网站| 欧美在线www| 国产精品一区二区黑丝| 亚洲网站视频福利| 亚洲精品中文字幕女同| 欧美 日韩 国产 一区| 激情久久婷婷| 美女视频黄免费的久久| 久久午夜精品| 亚洲精品护士| 91久久在线观看| 欧美精品在线视频观看| 99亚洲视频| 日韩午夜在线观看视频| 欧美日韩在线亚洲一区蜜芽| 亚洲综合大片69999| 亚洲综合视频网| 国产人成一区二区三区影院| 久久久精品日韩| 久久久久久午夜| 亚洲激情一区二区| 妖精成人www高清在线观看| 永久久久久久| 免费亚洲一区| 欧美电影在线播放| 正在播放亚洲| 亚洲欧美在线磁力| 国外视频精品毛片| 亚洲成人资源| 国产精品久久久久久久久久免费看 | 免费人成精品欧美精品| 久久久亚洲精品一区二区三区| 一区在线视频| 亚洲国产一二三| 欧美午夜精品理论片a级按摩| 亚洲欧美日韩中文视频| 亚洲欧美色一区| 亚洲福利视频网站| 亚洲久色影视| 国产一区二区精品久久99| 欧美成人综合| 国产精品久久国产三级国电话系列| 小辣椒精品导航| 麻豆视频一区二区| 午夜精品视频| 欧美二区乱c少妇| 久久av免费一区| 嫩草伊人久久精品少妇av杨幂| 亚洲宅男天堂在线观看无病毒| 欧美中文字幕在线观看| 日韩午夜剧场| 久久狠狠一本精品综合网| 999亚洲国产精| 久久久91精品国产一区二区精品| 亚洲作爱视频| 久久亚裔精品欧美| 欧美一级在线视频| 欧美精品久久99久久在免费线| 久久国产毛片| 欧美色综合网| 亚洲国产mv| 极品尤物av久久免费看| 亚洲视频网在线直播| 亚洲黑丝在线| 久久九九免费| 久久精品色图| 国产精品亚洲激情| 9色精品在线| 日韩亚洲视频| 欧美sm极限捆绑bd| 久久一区二区三区av| 国产精品视频免费| 日韩午夜高潮| 一本色道久久88综合亚洲精品ⅰ| 久久久综合网| 久久性色av| 韩国精品久久久999| 欧美一区二区高清在线观看| 午夜影视日本亚洲欧洲精品| 欧美国产激情二区三区| 亚洲国产mv| 亚洲国产精品久久91精品| 欧美一区二区三区视频在线| 亚洲欧美视频在线| 国产精品免费网站| 亚洲深夜福利在线| 亚洲一区二区黄| 国产精品成人一区| 亚洲视频在线观看三级| 亚洲欧美电影院| 国产精品亚发布| 欧美在线精品一区| 久久综合久久综合久久综合| 亚洲第一精品电影| 麻豆成人精品| 亚洲国产欧美在线人成| 亚洲裸体在线观看| 欧美日韩国产天堂| 亚洲网址在线| 久久午夜av| 亚洲黄色毛片| 欧美日韩第一区| 亚洲一级网站| 久久亚洲不卡| 99精品国产99久久久久久福利| 欧美日韩色一区| 亚洲欧美一区二区三区极速播放 | 理论片一区二区在线| 影音先锋日韩精品| 欧美精品成人| 在线性视频日韩欧美| 欧美亚洲免费在线| 亚洲第一福利社区| 欧美色网一区二区| 欧美中文字幕在线播放| 亚洲国产免费| 欧美专区亚洲专区| 91久久久在线| 国产精品乱码妇女bbbb| 久久久久久婷| 亚洲午夜在线观看| 免费成人黄色片| 亚洲一区二区三区在线播放| 国产一区日韩一区| 欧美另类一区二区三区| 香蕉乱码成人久久天堂爱免费| 欧美福利视频网站| 欧美一区成人| 这里只有精品视频| 一区精品在线| 国产精品免费看片| 欧美jizzhd精品欧美巨大免费| 亚洲一区二区三区在线| 欧美国产精品日韩| 欧美一区午夜精品| av不卡在线| 91久久国产综合久久91精品网站| 国产精品影片在线观看| 欧美精品粉嫩高潮一区二区 | 国产精品狠色婷| 久久久在线视频| 亚洲欧美日本另类| 一区二区三区国产在线观看| 欧美激情1区2区3区| 久久久成人网| 亚洲自拍偷拍网址| 一区二区三区精品视频在线观看| 亚洲国产高清高潮精品美女| 国产区亚洲区欧美区| 国产精品欧美日韩久久|