ubuntu 下 nginx 的安裝以及配置

原文如下:

http://imcn.me/html/y2012/11833.html

Nginx 是一個輕量級,以佔用系統資源少,運行效率而成爲web服務器的後起之秀,國內現在很多大型網站都以使用nginx,包括騰訊、新浪等大型信息網站,還有淘寶網站使用的是nginx二次開發的web服務器。

直接php+mysql這是Linux web服務器的黃金組合。今天我們一來學如何在ubuntu 12.04 中架設lnmp。

1. 使用官方PPA安裝 Nginx 最新版本,使用以下命令:
sudo add-apt-repository ppa:nginx/stable
sudo apt-get update
sudo apt-get install nginx

Nginx相關控制命令:
啓動 Nginx:
sudo /etc/init.d/nginx start
瀏覽器瀏覽運行情況輸入:http://localhost ;如果現實”Welcome to nginx!”,表明你的 Nginx 服務器安裝成功!
關閉 Nginx:sudo /etc/init.d/nginx stop;
重啓 nginx:sudo /etc/init.d/nginx restart;
2. 安裝 PHP,輸入以下命令:
sudo apt-get install php5-cli php5-cgi php5-fpm php5-mcrypt php5-mysql
配置Nginx站點,設置:
sudo vi /etc/nginx/sites-available/default
修改 “index” 爲:“index index.html index.htm index.php;”
刪除以下內容:

location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
}

測試,創建網站目錄
sudo mkdir /var/www/
建立一個虛擬站點:
sudo vi /etc/nginx/sites-available/default
修改root目錄: “root /var/www;”
建立一個測試頁面:
sudo vi /var/www/test.php
在測試頁面test.php中加入以下代碼:

<?php phpinfo();?>

重啓nginx
sudo /etc/init.d/nginx restart
瀏覽器輸入以下地址,看看有沒有安裝成功!

http://localhost/test.php

3.安裝 MySQL 數據庫:
sudo apt-get install mysql-server


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章