[筆記] ubuntu 11.4 安裝nginx, php. Install nginx, php on ubuntu server 11.4

環境提要:
VM
OS: ubuntu server 11.4 LTS,
不同版本ubuntu server,nginx 的設置不同,因此請先確認自己的伺服器版本是否相符合!

安裝nginx

sudo apt-get install nginxphp5-fpm

執行nginx

sudo /etc/init.d/nginx start<br></br>

[![](http://4.bp.blogspot.com/-37gCTgdCf3s/TdzNdv-8eQI/AAAAAAAAMAs/zBba5hwolO8/s1600/%25E5%259C%2596%25E7%2589%2587+1.jpg)](http://4.bp.blogspot.com/-37gCTgdCf3s/TdzNdv-8eQI/AAAAAAAAMAs/zBba5hwolO8/s1600/%25E5%259C%2596%25E7%2589%2587+1.jpg)
沒意外的話,就會出現上圖。 []() **修改設定檔** PATH: /etc/nginx/sites-available/default 如擔心意外可先備份此檔案,在此就不多解說設定作用,想要更多資料請[查詢nginx](http://www.lmgtfy.com/?q=nginx)。 `server {



listen 80; ## listen for ipv4

listen [::]:80 default ipv6only=on; ## listen for ipv6



server_name localhost;



access_log /var/log/nginx/localhost.access.log;



location / {

root /var/www;

index index.php index.html index.htm;

}



location /doc {

root /usr/share;

autoindex on;

allow 127.0.0.1;

deny all;

}



location /images {

root /usr/share;

autoindex on;

}



location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {

access_log off;

expires 30d;

root /var/www;

}



location ~ .php$ {

` fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi_params;`

}



location ~ /.ht {

deny all;

}

}
` **重新啟動nginx** `sudo /etc/init.d/nginx restart

`sudo /etc/init.d/php5-fpm restart
[![](http://2.bp.blogspot.com/-C7fh1I5MHAM/Td3CAVc05UI/AAAAAAAAMBE/5qd2eRmJ19w/s1600/%25E5%259C%2596%25E7%2589%2587+1.jpg)](http://2.bp.blogspot.com/-C7fh1I5MHAM/Td3CAVc05UI/AAAAAAAAMBE/5qd2eRmJ19w/s1600/%25E5%259C%2596%25E7%2589%2587+1.jpg)
PATH: /var/www/index.html, /var/www/phpinfo.php 產生一個預設網頁,以供待會測試。 index.html `



This is nginx TEST PAGE.





This is a nginx test page









` phpinfo.php `

` **開啟瀏覽器** 輸入VM server的IP,不清楚請參考[上一篇文章(VM Server 可以使用 SSH)](http://clonn.blogspot.com/2011/05/vm-server-ssh-let-you-vm-server-can-ssh.html)
[![](http://2.bp.blogspot.com/-IDz4DGBNjAQ/Td3DF1pyXpI/AAAAAAAAMBI/T9ng8sMdlzU/s1600/%25E5%259C%2596%25E7%2589%2587+2.jpg)](http://2.bp.blogspot.com/-IDz4DGBNjAQ/Td3DF1pyXpI/AAAAAAAAMBI/T9ng8sMdlzU/s1600/%25E5%259C%2596%25E7%2589%2587+2.jpg)
**恭喜完成安裝nginx** 預祝大家都能順利在ubuntu server上安裝成功,同時不要遇到任何問題,因為我安裝的時候沒有碰到任何問題啊….
還是很歡迎各位留言討論。** **資料來源: [玩物尚誌: 三分鐘快速安裝nginx+php5-fpm,以Ubuntu 11.04為例](http://blog.lyhdev.com/2011/05/nginxphp5-fpmubuntu-1104.html) [ ](http://blog.lyhdev.com/2011/05/nginxphp5-fpmubuntu-1104.html)

CaesarChi

Web developer, focus on website fullstack, special JavaScript, and love sharing developing experience and communicate with developers. http://about.me/clonn