安装Nginx
代码语言:javascript复制apt-get install nginx
(要最新版本下载下来编译吧) 装完应该能正常运行了。如果之前有装APACHE要改下端口。。。或者直接
代码语言:javascript复制apt-get remove apache2
/etc/init.d/nginx stop
/etc/init.d/nginx start
安装php-cgi
代码语言:javascript复制apt-get install php-cgi
改php-cgi的配置
Ubuntu下是/etc/php5/cgi/php.ini 之前有安装过php的话会复制apache的配置文件 打开cgi.fix_pathinfo选项:
代码语言:javascript复制cgi.fix_pathinfo=1;
改Nginx的fastcgi传递参数
Ubuntu下是/etc/nginx/fastcgi_params 默认应该已经设置好了,内容差不多就下面那样:
代码语言:javascript复制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/$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;
创建VHost配置(这里只说Ubuntu下的,也就路径和包含文件目录的区别了)
在/etc/nginx/sites-available/下创建服务器配置文件比如myserver
代码语言:javascript复制ln -n /etc/nginx/sites-available/myserver /etc/nginx/sites-enabled/myserver
其实懒的话直接创建在enabled里也没问题-。- 内容填:
代码语言:javascript复制server {
listen 80;
server_name myserver.com;
access_log /var/log/nginx/myserver.access.log;location / {
root /wwwroot/myserver;
index index.php;
autoindex off;
}
location ~ .php$ {
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME /wwwroot/myserver/$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
}
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/nginx-default;
}
# deny access to .htaccess files, if Apache’s document root
location ~ /.ht {
deny all;
}
}
安装spawn-fcgi
下载可到这里,这东西已经独立出来了 http://redmine.lighttpd.net/projects/spawn-fcgi/wiki 下完后解压编译
代码语言:javascript复制sudo ./configure –prefix=/usr/local
sudo make
sudo make install
启动spaw-fcgi
代码语言:javascript复制sudo spawn-fcgi -a 127.0.0.1 -p 9000 -u www-data -g www-data -f /usr/bin/php5-cgi -F 10
哦,对后面10进程不爽的人可以取消或是加到100
重启Nginx
代码语言:javascript复制/etc/init.d/nginx restart
定义下hosts就可以看结果啦
编辑/etc/hosts加入
代码语言:javascript复制127.0.0.1 myserver.com
然后打开浏览器就可以看结果啦~ 有问题欢迎指出~~