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

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 閱讀(480) 評論(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>
            亚洲精品久久久久久一区二区| 免费看亚洲片| 日韩视频免费| 欧美午夜一区二区| 亚洲愉拍自拍另类高清精品| 亚洲精品欧美在线| 国产精品欧美日韩| 久久精品官网| 麻豆成人在线| 一区二区欧美国产| 午夜视频精品| 亚洲国产女人aaa毛片在线| 亚洲狠狠婷婷| 国产精品成av人在线视午夜片| 亚洲欧美日韩综合一区| 亚洲性图久久| 性亚洲最疯狂xxxx高清| 亚洲二区在线视频| 日韩一二在线观看| 亚洲一区精彩视频| 亚洲第一精品久久忘忧草社区| 亚洲高清av在线| 国产精品亚洲а∨天堂免在线| 久久综合精品国产一区二区三区| 女女同性女同一区二区三区91| 亚洲视频一区| 美女精品视频一区| 亚洲专区欧美专区| 久久精品中文字幕一区二区三区| 亚洲另类自拍| 久久久xxx| 亚洲欧美另类在线观看| 鲁大师成人一区二区三区| 亚洲愉拍自拍另类高清精品| 久久在线免费观看视频| 欧美日韩性生活视频| 久久婷婷国产综合尤物精品| 欧美三级电影网| 免费视频一区| 国产日韩精品一区二区三区在线| 亚洲欧洲免费视频| 在线免费观看日本一区| 亚洲美女av在线播放| 亚洲国产成人在线播放| 欧美一区二区高清| 欧美日韩mp4| 欧美高清不卡在线| 国产一区二区在线观看免费播放 | 国产精品久久福利| 男同欧美伦乱| 国产一区二区精品久久91| 亚洲最新中文字幕| 欧美激情第六页| 美女国产一区| 狠狠色2019综合网| 午夜在线精品偷拍| 欧美呦呦网站| 国产情人节一区| 亚洲欧美综合| 欧美一区二区三区男人的天堂| 欧美日韩国产美女| 亚洲美女精品成人在线视频| 最近中文字幕mv在线一区二区三区四区| 亚洲在线日韩| 国产精品s色| 日韩午夜激情| 亚洲一区二区三区777| 欧美日韩成人| 在线视频欧美日韩| 亚洲一区二区三区四区视频| 欧美日韩情趣电影| 99国产精品99久久久久久粉嫩| 一本色道久久99精品综合| 欧美激情第五页| 亚洲日韩欧美一区二区在线| 麻豆精品视频在线| 91久久国产综合久久蜜月精品| 91久久嫩草影院一区二区| 欧美风情在线观看| 999亚洲国产精| 亚洲欧美激情四射在线日 | 久久精品视频网| 国产日韩一区二区| 久久久久女教师免费一区| 欧美ed2k| 9久re热视频在线精品| 欧美日韩在线另类| 亚洲一区二区三区四区视频 | 亚洲精品国产精品国自产在线| 欧美国产视频在线| 亚洲视频中文字幕| 国产午夜精品久久| 久久综合一区二区三区| 亚洲精品视频免费观看| 亚洲欧美激情一区二区| 国产一区二区主播在线| 美女免费视频一区| 99国产欧美久久久精品| 久久aⅴ国产欧美74aaa| 亚洲国产日韩精品| 国产精品久久久久久久久借妻| 亚洲欧美中文字幕| 亚洲激情av| 久久国产日韩| 在线视频精品一| 国外视频精品毛片| 欧美日韩一区二区三区免费看| 欧美在线欧美在线| 亚洲精品美女在线观看| 久久精品av麻豆的观看方式| 亚洲美女视频| 禁久久精品乱码| 国产精品蜜臀在线观看| 美女视频黄免费的久久| 亚洲亚洲精品三区日韩精品在线视频| 久久视频在线免费观看| 亚洲午夜视频在线观看| 亚洲电影免费观看高清完整版| 国产精品久久久久久久久久妞妞| 久久人人爽爽爽人久久久| 亚洲一区二区三区久久| 亚洲精品极品| 欧美wwwwww| 久久综合伊人77777蜜臀| 午夜精品福利视频| 亚洲看片网站| 亚洲国产mv| 国内外成人在线视频| 国产精品久久| 欧美日韩高清在线| 欧美v国产在线一区二区三区| 亚洲欧美日韩一区二区三区在线| 亚洲国产乱码最新视频| 久久久久久久一区二区三区| 亚洲欧美日韩精品综合在线观看| 一区二区精品国产| 亚洲日本黄色| 欧美不卡视频| 嫩草影视亚洲| 开元免费观看欧美电视剧网站| 久久精品卡一| 久久久福利视频| 欧美在线视频免费播放| 亚洲欧美国产日韩天堂区| 亚洲一区二区三区四区在线观看 | 亚洲国产精品国自产拍av秋霞| 久久综合精品国产一区二区三区| 久久精品日韩欧美| 国产精品久久久久影院亚瑟| 欧美日韩精品在线| 欧美日韩一区二区在线| 国产精品久久久久久一区二区三区| 欧美精品播放| 欧美日韩亚洲91| 国产精品日本| 国产一区二区三区观看 | 欧美成人精品不卡视频在线观看| 久久精品一区二区三区四区| 久久久免费av| 亚洲人线精品午夜| 亚洲午夜av电影| 欧美在线电影| 欧美成人精品一区| 欧美日韩国内| 国产美女在线精品免费观看| 国产亚洲精品美女| 最新成人av网站| 亚洲欧美日韩电影| 久久久蜜臀国产一区二区| 欧美阿v一级看视频| 亚洲乱码国产乱码精品精天堂| 一区二区三区欧美在线观看| 亚洲欧美日韩电影| 久久免费视频观看| 欧美日韩国产成人精品| 国产伦精品一区| 亚洲电影天堂av| 亚洲一区视频| 欧美 日韩 国产 一区| 亚洲人成啪啪网站| 性18欧美另类| 欧美激情综合五月色丁香| 国产精品久99| 亚洲国产精品一区二区www在线 | 这里只有精品丝袜| 久久国产欧美日韩精品| 亚洲国产精品毛片| 亚洲欧美日韩国产一区| 免费中文日韩| 国产亚洲一区二区三区| 亚洲精品影视在线观看| 久久久xxx| 一本色道综合亚洲| 久久一区二区三区四区| 国产精品视频一区二区高潮| 亚洲国产成人av| 久久久国产成人精品| 一区二区三区鲁丝不卡| 噜噜爱69成人精品| 国产在线观看精品一区二区三区 |