Archive for 10月, 2008

Gentoo 下安装 git 及解决 error: git was compiled without libcurl support. 错误

使用
emerge -av dev-util/git
就可以安装,不过在安装前最好先使用
# echo “dev-util/git webdav” >> /etc/portage/package.use
设置 webdav 标志。不然使用http地址时会出现错误。

gamexg@GGentoo ~/git $ git-clone http://www.bitsun.com/git/gittutorcn.git
Initialized empty Git repository in /home/gamexg/git/gittutorcn/.git/
error: git was compiled without libcurl support.
fatal: Don’t know how to clone http://www.bitsun.com/git/gittutorcn.git

Comments (1) »

linux 下的图形化分区管理工具 Gparted

比较好用,属于 gnome。
gentoo下的安装命令 sudo emerge gparted

No comment »

Gentoo 下安装 Firefox 3 及(‘ebuild’, ‘/’, ‘www-client/mozilla-firefox-2.0.0.17’, ‘merge’) pulled in by (‘installed’, ‘/’, ‘gnome-extra/yelp-2.22.1-r2’, ‘nomerge’) 问题解决。

在 /etc/portage/package.keywords 添加下面的内容。

www-client/mozilla-firefox ~x86
dev-libs/nspr ~x86
dev-libs/nss ~x86
net-libs/xulrunner ~x86

在 /etc/make.conf 里的 USE 变量添加 xulrunner ,然会执行 sudo emerge firefox 就可以了。

如果忘了添加 xulrunner 会出现 yelp 依赖 firefox2 的现象出现下面的错误(添加上xulrunner就可以解决):

gamexg@GGentoo ~ $ sudo emerge -p –update –deep –newuse world

These are the packages that would be merged, in order:

Calculating world dependencies –
!!! Multiple versions within a single package slot have been
!!! pulled into the dependency graph:

www-client/mozilla-firefox:0

(‘ebuild’, ‘/’, ‘www-client/mozilla-firefox-2.0.0.17’, ‘merge’) pulled in by
(‘installed’, ‘/’, ‘gnome-extra/yelp-2.22.1-r2’, ‘nomerge’)

(‘installed’, ‘/’, ‘www-client/mozilla-firefox-3.0.3’, ‘nomerge’) (no parents)

It may be possible to solve this problem by using package.mask to
prevent one of those packages from being selected. However, it is also
possible that conflicting dependencies exist such that they are
impossible to satisfy simultaneously. If such a conflict exists in the
dependencies of two different packages, then those packages can not be
installed simultaneously.

For more information, see MASKED PACKAGES section in the emerge man page
or refer to the Gentoo Handbook.

… done!
[ebuild UD] www-client/mozilla-firefox-2.0.0.17 [3.0.3] USE=”-debug% -filepicker% -moznopango% -xforms% -xinerama% -xprint%” LINGUAS=”-bg%”

Comments (1) »

Gentoo 问题:checking for pygtk 2.8.0 installed for python 2.4… not found configure: error: required pygtk version not found

安装 gnome 时出现错误,内容:
checking for pygtk 2.8.0 installed for python 2.4… not found
configure: error: required pygtk version not found

这个应该是升级到 python2.5 后,没有运行 python-updater 的原因。

No comment »

使用谷歌文件发布 wordpress 博客

进入谷歌文件设置,选择博客设置=>编辑信息。

选择  “我自己的服务器/自定义” ,API 使用 MetaWeblog API 使用 MovableType 不支持标题)。
我的 URL 是 http://gamexg-cw.cn/xmlrpc.php 自己的照着改就可以了。
 用户名和密码填博客的用户名和密码。
博客 ID/标题 留空。现在点测试如果没问题就点击确定保存设置。

现在已经设置完成了博客信息,随便建立一个文件写点内容就可以尝试发布了。
打开想发到博客的文件,选择共享=>以网页形式发布=>张贴到博客就可以了。
这篇文章就是这样发布的。

一些问题:目录和标签并不能支持,不过我记得有个插件可以自动生成标签(也可以使用内部标签)。

No comment »

web.py 文档中文翻译:web.py 模板系统 (代码名称templetor)

原文:web.py templating system (codename: templetor)

There are almost as many Python templating systems as there are web frameworks (and, indeed, it seems like many templating systems are adopting web framework-like features), so it is with some trepidation that I work on a new one. Sadly, again I find that my requirements are met by nothing else:
Python 模板系统几乎和web框架一样多(甚至一些 web 框架的特色是拥有多个模板系统。)我总是带着忧虑使用一个新的。令人沮丧的,但是我发现我只需要:

1. The templating system has to look decent. No crud.
1. 这个模板系统看起来不错。不混乱。
2. Reuse Python terms and semantics as much as possible.
2. 尽可能的使用 Python 关键字和语法。
3. Expressive enough to do real computation.
3. 充足的表达式用于真正使用
4. Usable for any text language, not just HTML and XML.
4. 可用于任何文本语言,不要只支持 HTML 和 XML。

And requirements for the implementation as well:

和良好的可用性:

1. Sandboxable so that you can let untrusted users write templates.
1. 沙盒支持,使得你可以允许未信任的用户写模板。
2. Simple and fast implementation.
2. 简单和快速的使用

So here’s my entry.
那么此时我参与。
Variable substitution
替换变量

[coolcode lang=”python”]
Look, a $string.
Hark, an ${arbitrary + expression}.
Gawk, a $dictionary[key].function(‘argument’).
Cool, a $(limit)ing.

Stop, \$money isn’t evaluated.
[/coolcode]

We use basically the same semantics as (rejected) PEP 215. Variables can go anywhere in a document.
我们使用基本上和(不合格?) PEP 215 一样的语义。变量可以在文档的任何地方。
Newline suppression
新行抑制

[coolcode lang=”python”]
If you put a backslash \
at the end of a line \
(like these) \
then there will be no newline.
[/coolcode]

renders as all one line.
所有的显示在一行。
Expressions
表达式

[coolcode lang=”python”]
Here are some expressions:

$for var in iterator: I like $var!

$if times > max:
Stop! In the name of love.
$else:
Keep on, you can do it.
[/coolcode]

That’s all, folks.

All your old Python friends are here: if, while, for, else, break, continue, and pass also act as you’d expect. (Obviously, you can’t have variables named any of these.) The Python code starts at the $ and ends at the :. The $ has to be at the beginning of the line, but that’s not such a burden because of newline suppression (above).
你所有的旧的 Python 朋友在这里:if, while, for, else, break, continue, 和 pass 也为你预期的动作。(明显你不能将变量名称设置为这些。)这些 Python 代码以 $ 开头,以 : 结尾。 $ 在行开始位置,只是叠句因为新行抑制所以不是这样(上面)

Also, we’re very careful about spacing — all the lines will render with no spaces at the beginning. (Open question: what if you want spaces at the beginning?) Also, a trailing space might break your code.
同样,我们非常小心空白 – 所有的行会呈现为开始出没有空白。(问题:如果你需要行开始出有空白怎么做?)同样,结尾处的空白可终止你的代码。

There are a couple changes from Python: for and while now take an else clause that gets called if the loop is never evaluated.
有两个和python不同的更改:for 和 while 现在获得 else 子句,它将在从未执行循环体内代码时执行。

(Possible feature to add: Django-style for loop variables.)
(可能增加的特征:Django-style 循环变量)
Comments
注释

[coolcode lang=”python”]
$# Here’s where we hoodwink the folks at home:

Please enter in your deets:

CC: [ ] $#this is the important one
SSN: $#Social Security Number#$ [ ]
[/coolcode]

Comments start with $# and go to #$ or the end of the line, whichever is first.
Code

注释开始与 $# , 结束与 #$ 或行结尾。

NOTE: This feature has not been implemented in the current web.py implementation of templetor.
注释:这个特征不受到通用的支持。

[coolcode lang=”python”]
Sometimes you just need to break out the Python.

$ mapping = {
$ ‘cool’: [‘nice’, ‘sweet’, ‘hot’],
$ ‘suck’: [‘bad’, ‘evil’, ‘awful’]
$ }

Isn’t that $mapping[thought]?
That’s$ del mapping $ fine with me.

$ complicatedfunc()

$ for x in bugs:
$ if bug.level == ‘severe’:
Ooh, this one is bad.
$ continue
And there’s $x…
[/coolcode]

Body of loops have to be indented with exactly 4 spaces.
循环体的缩进格式是4个空白。

Code begins with a $ and a space and goes until the next $ or the end of the line, whichever comes first. Nothing ever gets output if the first character after the $ is a space (so complicatedfunc above doesn’t write anything to the screen like it might without the space).
代码开始与 $ 和 一个空白 ,直到下一个 $ 或者 行结束。绝不输出$之后的第一个空白(那么执行上面代码绝不输出空白)
Python integration
Python 集成

A template begins with a line like this:
一个模板以这个一样的行开始:

[coolcode lang=”python”]
$def with (name, title, company=’BigCo’)
[/coolcode]

which declares that the template takes those arguments. (The with keyword is special, like def or if.)
声明使用哪些参数。(with 关键字是专用的, like def or if.)

Don’t forget to put spaces in the definition
不要忘记为这个定义放置空格

The following will not work:
下面的必定不能工作:

[coolcode lang=”python”]
$def with (name,title,company=’BigCo’)
[/coolcode]

Inside Python, the template looks like a function that takes these arguments. It returns a storage object with the special property that evaluating it as a string returns the value of the body of the template. The elements in the storage object are the results of the defs and the sets.
这个模板的样子像 Python 内部一个程序使用这些参数。它返回一个和这个模板相关的对象,这个对象模仿字符串的行为。The elements in the storage object are the results of the defs and the sets.

Perhaps an example will make this clearer. Here’s a template, “entry”:
大概一个示例更清晰。像这个例子,‘entry’:

[coolcode lang=”python”]
$def with (post)

$var title: $post.title

$markdown(post.body)

[/coolcode]

Here’s another; “base”:
这里有另外一个;’base’:

[coolcode lang=”python”]
$def with (self)

$self.title

$self.title

$:self
[/coolcode]

Now let’s say we compile both from within Python, the first as entry, the second as base. Here’s how we might use them:
现在假定说我们在 Pyhon 中使用两者,第一个是 entry,第二个是 base。我们应该使用:

[coolcode lang=”python”]
print base( entry( post ) )
[/coolcode]

entry takes the argument post and returns an object whose string value is a bit of HTML showing the post with its title in the property title. base takes this object and places the title in the appropriate place and displays the page itself in the body of the page. The Python code prints out the result.

_Where did markdown come from? It wasn’t passed as an argument._ You can pass a list of functions and variables to the template compiler to be made globally available to templates. Why $:self? See below

Here’s an example:

[coolcode lang=”python”]
import template
render = template.render(‘templates/’)
template.Template.globals[‘len’] = len

print render.base(render.message(‘Hello, world!’))
[/coolcode]

The first line imports templetor. The second says that our templates are in the directory templates/. The third give all our templates access to the len function. The fourth grabs the template message.html, passes it the argument ‘Hello, world!’, passes the result of rendering it to the template base.html and prints the result. (If your templates don’t end in .html or .xml, templetor will still find them, but it won’t do its automatic HTML-encoding.)

Turning Off Filter

By default template.render will use web.websafe filter to do HTML-encoding. To turn it off, put a : after the $ as in:

[coolcode lang=”python”]
$:form.render()
[/coolcode]

Output from form.render() will be displayed as is.

[coolcode lang=”python”]
$:fooBar $# fooBar = lorem ipsum
[/coolcode]

Output from variable in template will be displayed as is.
Including / nesting templates

If you want to nest one template within another, you nest the render() calls, and then include the variable (unfiltered) in the page. In your handler:

[coolcode lang=”python”]
print render.foo(render.bar())
[/coolcode]

or (to make things a little more clear):

[coolcode lang=”python”]
barhtml = render.bar()
print render.foo(barhtml)
[/coolcode]

Then in the template foo.html:

[coolcode lang=”python”]
$def with (bar)
html goes here
$:bar
more html
[/coolcode]

This replaces the $:bar with the output of the render.bar() call (which is why it must be $:/unfiltered, so that you get un-encoded HTML (unless you want something else of course)). You can pass variables in, in the same way:

[coolcode lang=”python”]

print render.foo(render.bar(baz), qux)
[/coolcode]

In the template bar (bar.html):

[coolcode lang=”python”]
$def with (baz)
bar stuff goes here + baz
[/coolcode]

In template foo (foo.html):

[coolcode lang=”python”]
$def with (bar, qux)
html goes here
$:bar
Value of qux is $qux
[/coolcode]

No comment »

nginx中文翻译: location 指令

location

syntax: location [=|~|~*|^~] /uri/ { … }
语法:location [=|~|~*|^~] /uri/ { … }

default: no
默认:否

context: server
上下文:server

This directive allows different configurations depending on the URI. It can be configured using both conventional strings and regular expressions. To use regular expressions, you must use the prefix ~* for case insensitive match and ~ for case sensitive match.
这个指令随URL不同而接受不同的结构。你可以配置使用常规字符串和正则表达式。如果使用正则表达式,你必须使用 ~* 前缀选择不区分大小写的匹配或者 ~ 选择区分大小写的匹配。

To determine which location directive matches a particular query, the conventional strings are checked first. Conventional strings match the beginning portion of the query and are case-sensitive – the most specific match will be used (see below on how nginx determines this). Afterwards, regular expressions are checked in the order defined in the configuration file. The first regular expression to match the query will stop the search. If no regular expression matches are found, the result from the convention string search is used.
确定 哪个location 指令匹配一个特定指令,常规字符串第一个测试。常规字符串匹配请求的开始部分并且区分大小写,最明确的匹配将会被使用(查看下文明白 nginx 怎么确定它)。然后正则表达式按照配置文件里的顺序测试。找到第一个比配的正则表达式将停止搜索。如果没有找到匹配的正则表达式,使用常规字符串的结果。

There are two ways to modify this behavior. The first is to use the prefix “=”, which matches an exact query only. If the query matches, then searching stops and the request is handled immediately. For example, if the request “/” occurs frequently, then using “location = /” will expedite the processing of this request.
有两个方法修改这个行为。第一个方法是使用 “=”前缀,将只执行严格匹配。如果这个查询匹配,那么将停止搜索并立即处理这个请求。例子:如果经常发生”/”请求,那么使用 “location = /” 将加速处理这个请求。

The second is to use the prefix ^~. This prefix is used with a conventional string and tells nginx to not check regular expressions if the path provided is a match. For instance, “location ^~ /images/” would halt searching if the query begins with /images/ – all regular expression directives would not be checked.
第二个是使用 ^~ 前缀。如果把这个前缀用于一个常规字符串那么告诉nginx 如果路径匹配那么不测试正则表达式。

Furthermore it is important to know that NGINX does the comparison not URL encoded, so if you have a URL like “/images/%20/test” then use “/images/ /test” to determine the location.
而且它重要在于 NGINX 做比较没有 URL 编码,所以如果你有一个 URL 链接’/images/%20/test’ , 那么使用 “images/ /test” 限定location。

To summarize, the order in which directives are checked is as follows:
总结,指令按下列顺序被接受:

1. Directives with the = prefix that match the query exactly. If found, searching stops.
1. = 前缀的指令严格匹配这个查询。如果找到,停止搜索。
2. All remaining directives with conventional strings, longest match first. If this match used the ^~ prefix, searching stops.
2. 剩下的常规字符串,长的在前。如果这个匹配使用 ^~ 前缀,搜索停止。
3. Regular expressions, in order of definition in the configuration file.
3. 正则表达式,按配置文件里的顺序。
4. If #3 yielded a match, that result is used. Else the match from #2 is used.
4. 如果第三步产生匹配,则使用这个结果。否则使用第二步的匹配结果。

Example:
例子:

location = / {
# matches the query / only.
# 只匹配 / 查询。
[ configuration A ]
}
location / {
# matches any query, since all queries begin with /, but regular
# expressions and any longer conventional blocks will be
# matched first.

# 匹配任何查询,因为所有请求都已 / 开头。但是正则表达式规则和长的块规则将被优先和查询匹配。
[ configuration B ]
}
location ^~ /images/ {
# matches any query beginning with /images/ and halts searching,
# so regular expressions will not be checked.

# 匹配任何已 /images/ 开头的任何查询并且停止搜索。任何正则表达式将不会被测试。
[ configuration C ]
}
location ~* \.(gif|jpg|jpeg)$ {
# matches any request ending in gif, jpg, or jpeg. However, all
# requests to the /images/ directory will be handled by
# Configuration C.

# 匹配任何已 gif、jpg 或 jpeg 结尾的请求。然而所有 /images/ 目录的请求将使用 Configuration C。
[ configuration D ]
}

Example requests:
例子请求:

*

/ -> configuration A
*

/documents/document.html -> configuration B
*

/images/1.gif -> configuration C
*

/documents/1.jpg -> configuration D

Note that you could define these 4 configurations in any order and the results would remain the same.
注意:按任意顺序定义这4个配置结果将仍然一样。

No comment »

Pyrex 安装的小问题: MinGW 配置修改

为 pyrex 安装 MinGW 需要将
mingw\lib\gcc\mingw32\3.2.4\specs
文件里的”-lmsvcrt” 修改为 “-lmsvcr71”.

原因是 python 使用 msvcr71 ,使用不同版本的库会影响稳定性。

No comment »

Windows 下以 nginx proxy模式运行 web.py

注意:更好的方式是使用WSGI,但是没有发现windows版本(我也只是开发用,实际建议使用linux+WSGI)。这里使用的是代理模式。(windows 下最好使用fastcgi模式,参考Windows 下以 nginx + fastcgi 运行 Django 或 web.py。这里只是一个功能说明,如果后端使用apache等不支持 fastcgi 等模式时可以使用本方法。)

从 http://www.saddi.com/software/flup/dist/ 下载 flup 并执行 setup.py install 安装。
用压缩软件打开 flup-1.0.1-py2.5.egg 修改 fcgi_base.py 文件,将 isFCGI = True 改成 isFCGI = False 并注释掉以下代码:
[coolcode]
sock = socket.fromfd(FCGI_LISTENSOCK_FILENO, socket.AF_INET,
socket.SOCK_STREAM)
try:
sock.getpeername()
except socket.error, e:
if e[0] == errno.ENOTSOCK:
# Not a socket, assume CGI context.
isFCGI = False
elif e[0] != errno.ENOTCONN:
raise
[/coolcode]
从 http://www.kevinworthington.com/category/computers/nginx/ 下载 nginx Windows 版本的安装程序。
运行并安装。
打开配置文件nginx/conf/nginx.conf 修改为:

[coolcode download=”nginx.conf”]
#user nobody;
worker_processes 1;

#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;

#pid logs/nginx.pid;

events {
worker_connections 64;
}

http {
include mime.types;
default_type application/octet-stream;

#log_format main ‘$remote_addr – $remote_user [$time_local] $request ‘
# ‘”$status” $body_bytes_sent “$http_referer” ‘
# ‘”$http_user_agent” “$http_x_forwarded_for”‘;

#access_log logs/access.log main;

sendfile on;
#tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 65;

#gzip on;

server {
listen 80;
server_name localhost;

root /cygdrive/D/html;
index index.html index.htm;

charset utf-8;

#access_log logs/host.access.log main;

# static resources
location ~* ^.+\.(html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js)$
{
expires 30d;
break;
}

location / {
proxy_pass http://127.0.0.1:8061;
}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}

# deny access to .htaccess files, if Apache’s document root
# concurs with nginx’s one
#
#location ~ /\.ht {
# deny all;
#}
}

# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;

# location / {
# root html;
# index index.html index.htm;
# }
#}

# HTTPS server
#
#server {
# listen 443;
# server_name localhost;

# ssl on;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;

# ssl_session_timeout 5m;

# ssl_protocols SSLv2 SSLv3 TLSv1;
# ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
# ssl_prefer_server_ciphers on;

# location / {
# root html;
# index index.html index.htm;
# }
#}

}
[/coolcode]

现在建立a.py 内容是
[coolcode lang=”python” download=”a.py”]
#!/usr/bin/env python
import web
urls = (
‘/.*’, ‘hello’
)
class hello:
def GET(self):
print ‘aaa’
if __name__ == “__main__”: web.run(urls, globals())
[/coolcode]
然后重启 nginx 并执行 a.py 8061

现在就可以访问了。静态文件由nginx负责,动态内容由a.py负责。

主目录为d:\html,定义是:
root /cygdrive/D/html;

附一个参数列表(发现一般是使用include 包含配置文件fastcgi_params):
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;

fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;

fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;

fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
# PHP only, required if PHP was built with –enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;

Comments (1) »

Windows 下以 nginx + fastcgi 运行 Django 或 web.py

从 http://www.saddi.com/software/flup/dist/ 下载 flup 并执行 setup.py install 安装。

从 http://www.kevinworthington.com/category/computers/nginx/ 下载nginx Windows版本的安装程序。
运行并安装。
打开配置文件 nginx/conf/nginx.conf 修改为:
[coolcode download=”nginx.conf”]
#user nobody;
worker_processes 1;

#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;

#pid logs/nginx.pid;

events {
worker_connections 64;
}

http {
include mime.types;
default_type application/octet-stream;

#log_format main ‘$remote_addr – $remote_user [$time_local] $request ‘
# ‘”$status” $body_bytes_sent “$http_referer” ‘
# ‘”$http_user_agent” “$http_x_forwarded_for”‘;

#access_log logs/access.log main;

sendfile on;
#tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 65;

#gzip on;

server {
listen 80;
server_name localhost;

root /cygdrive/D/html;
index index.html index.htm;

charset utf-8;

#access_log logs/host.access.log main;

# 静态资源
location ~* ^.+\.(html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js)$
{
expires 30d;
break;
}

location / {
# 指定 fastcgi 的主机和端口
fastcgi_pass 127.0.0.1:8051;
fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
fastcgi_pass_header Authorization;
fastcgi_intercept_errors off;
}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}

# deny access to .htaccess files, if Apache’s document root
# concurs with nginx’s one
#
#location ~ /\.ht {
# deny all;
#}
}

# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;

# location / {
# root html;
# index index.html index.htm;
# }
#}

# HTTPS server
#
#server {
# listen 443;
# server_name localhost;

# ssl on;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;

# ssl_session_timeout 5m;

# ssl_protocols SSLv2 SSLv3 TLSv1;
# ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
# ssl_prefer_server_ciphers on;

# location / {
# root html;
# index index.html index.htm;
# }
#}

}
[/coolcode]
现在重启启动 nginx 后在Django项目下执
.\manage.py runfcgi method=threaded host=127.0.0.1 port=8051
就可以了。

这里没有设置 media 目录,现在是以扩展名来分辨是不是转发到Django的程序处理。
想要只允许 nginx 处理media 目录只需要将
location ~* ^.+\.(html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js)$
换成
location ~ ^/media/
就可以了。

主目录为d:\html,定义是:
root /cygdrive/D/html;

如果运行 web.py 的项目
[coolcode lang=”python” download=”a.py”]
#!/usr/bin/env python
import web
urls = (
‘/.*’, ‘hello’
)
class hello:
def GET(self):
print ‘aaa’
if __name__ == “__main__”: web.run(urls, globals())
[/coolcode]
只需要把执行
.\manage.py runfcgi method=threaded host=127.0.0.1 port=8051
换成执行
a.py 8051 fastcgi
就可以了。

附一个参数列表(发现一般是使用include 包含配置文件fastcgi_params):
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;

fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;

fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;

fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
# PHP only, required if PHP was built with –enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;

Comments (1) »