$ sudo -s
//添加源
$ sudo echo "deb http://ppa.launchpad.net/nginx/stable/ubuntu lucid main" > /etc/apt/sources.list.d/nginx-stable-lucid.list
$ sudo echo "deb http://ppa.launchpad.net/nginx/php5/ubuntu lucid main" > /etc/apt/sources.list.d/nginx-stable-lucid.list
$ sudo echo "deb-src http://ppa.launchpad.net/nginx/php5/ubuntu lucid main" > /etc/apt/sources.list.d/nginx-stable-lucid.list
$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys C300EE8C
//更新源
$ sudo aptitude update
//安装nginx
$ sudo aptitude install nginx
//安装php及相关依赖
$ sudo aptitude install php5 php5-cgi php5-cli php5-mysql php5-memcached php5-gd php5-curl php-pear php-apc php-fpm
//启动
service nginx start
service php-fpm start
//测试
$ ps aux | grep nginx
root 14051 0.0 0.1 71092 1568 ? Ss May28 0:00 nginx: master process /usr/sbin/nginx
www-data 14052 0.1 0.2 72496 3568 ? S May28 3:47 nginx: worker process
$ ps aux | grep php
root 14238 0.0 0.3 182432 4944 ? Ss May28 0:25 php-fpm: master process (/etc/php5/fpm/main.conf)
www-data 14255 0.1 3.1 192428 48292 ? S May28 4:54 php-fpm: pool www
www-data 14256 0.1 4.0 207328 62988 ? S May28 4:43 php-fpm: pool www
www-data 14258 0.1 3.8 202720 59212 ? S May28 4:36 php-fpm: pool www
www-data 14291 0.1 3.6 199648 55496 ? S May28 4:39 php-fpm: pool www
www-data 14293 0.1 3.3 196576 52260 ? S May28 4:51 php-fpm: pool www
www-data 14294 0.1 3.4 196576 52952 ? S May28 4:47 php-fpm: pool www
www-data 14297 0.1 4.5 214756 70368 ? S May28 4:34 php-fpm: pool www
www-data 14298 0.1 3.1 192336 48900 ? S May28 4:46 php-fpm: pool www
www-data 14299 0.1 3.1 192332 48856 ? S May28 5:05 php-fpm: pool www
www-data 14300 0.1 2.9 191044 46132 ? S May28 4:58 php-fpm: pool www
//nginx 配置 路径 /etc/nginx/sites-avilable/example.com
$ vi /etc/nginx/sites-avilable/example.com
server {
listen 80;
server_name www.example.com;
rewrite ^(.*) http://example.com$1 permanent;
}
server {
listen 80;
server_name example.com;
access_log /var/log/nginx/example.com.access.log;
error_log /var/log/nginx/example.com.error.log;
root /var/www/example.com;
index index.php index.html;
try_files $uri $uri/ /index.php?q=$1;
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
location ~ /\.ht {
deny all;
}
#添加软链
$ ln -s /etc/nginx/sites-availabe/example.com /etc/nginx/sites-enabled/example.com
#重启nginx
$service nginx restart
#配置hosts
$ vi /etc/hosts //添加 127.0.0.1 example.com
#完成
访问:example.com
#1、 安装过程源找不到,请到“新立得”里手工加上
#2、 安装过程提示nginx-full/nginx错误导致php-fpm安装失败,请到“新立得”里重新安装php-fpm按提示强制删除nginx,然后再安装nginx。
#3、注意测试地址在:/var/www/example.com/XXXX.html