1.安装nginx
运行:
sudo apt-get intsall nginx
2.启动nginx
运行:
sudo /etc/init.d/nginx start
3.查看网页
浏览器里输入http://localhost/
提示 Welcome to nginx说明安装成功了!
提示:在ubuntu11.04中nginx 默认网站目录为
/usr/share/nginx/www
这个是被我改了HTML的。
不要高兴的太早,要想支持PHP还要经历一番折腾。
4.安装PHP5
apt-get install php5-fpm
PHP – FPM是一个守护进程(与初始化脚本 / etc/init.d/php5-fpm )运行FastCGI服务器上的端口 9000 。
5.nginx的配置
配置文件/etc/nginx/nginx.conf
vi /etc/nginx/nginx.conf
你可以通过http://wiki.codemongers.com/NginxFullExample和http://wiki.codemongers.com/NginxFullExample2网址了解更多配置信息。
增加工作进程,可选,可以不修改
worker_processes 5;
keepalive_timeout 2;
默认虚拟主机配置文件地址/etc/nginx/sites-available/default
CODE:
vi /etc/nginx/sites-available/default
server { listen 80; ## listen for ipv4; this line is default and implied listen [::]:80 default ipv6only=on; ## listen for ipv6 root /usr/share/nginx/www; index index.php index.html index.htm; # Make site accessible from http://localhost/ server_name _; location / { # First attempt to serve request as file, then # as directory, then fall back to index.html try_files $uri $uri/ /index.html; } location /doc { root /usr/share; autoindex on; allow 127.0.0.1; deny all; } location /images { root /usr/share; autoindex 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 /usr/share/nginx/www; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ /.php$ { # proxy_pass [url]http://127.0.0.1[/url]; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ /.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi_params; } # deny access to .htaccess files, if Apache’s document root # concurs with nginx’s one # location ~ //.ht { deny all; } } |
6.重启命令
ngnix重新加载一下配置
nginx -s reload
最后重启生效
sudo /etc/init.d/nginx restart
sudo /etc/init.d/php5-fpm restart