自己有个 vps,web 服务器安装 nginx。现在帮同事搞个 blog(自己的 blog 还没挂到 vps 上呢)。要支持 php,还不知道 wordpress rewrite 规则,所以自己的blog没搬过去就是因为这个原因。 vps 上也装有 lighttpd,搞了一个晚上 lighttpd 还没安装上 wordpress 放弃。改用 nginx(反正 lighttpd 支持的 php 也是通过 nginx 代理过去,干脆用nginx 支持php 行了 )。 php 安装参数如: ./configure --prefix=/usr/local/php --enable-fastcgi --with-mysql=/usr/local/mysql --enable-zend-multibyte --with-config-file-path=/usr/local/php/conf --enable-discard-path --enable-force-cgi-redirect 启动php-cgi: /usr/local/php/bin/php-cgi -b 127.0.0.1:9000nginx fastcgi 配置:/usr/local/nginx/conf/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_FILENAME $document_root$fastcgi_script_name; 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/$nginx_version; 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; 基本上是官方自带的,我只加了 SCRIPT_FILENAME。 nginx 配置: server { listen 80; server_name www.example.com; access_log logs/example.access.log main; server_name_in_redirect off; root /home/www/wordpress; index index.php index.html index.htm; location / { try_files $uri $uri/ /index.php?q=$uri&$args; } location ~ \.php$ { include fastcgi_params; fastcgi_pass 127.0.0.1:9000; } } 用 try_files 太简单了。都不用 rewrite 规则。 测试过可行的。 延伸:当然在生产环境像上面简单地用 php-cgi 是不行的。我用 spawn-fcgi 管理 php-cgi。 (责任编辑:IT) |