1、添加ubuntu nginx更新鏡像源
sudo vi /etc/opt/source.list
添加:deb http://nginx.org/packages/ubuntu/ precise nginx
deb-src http://nginx.org/packages/ubuntu/ precise nginx
2、更新軟件包源:
sudo apt-get update
出現如下錯誤:W: GPG 錯誤:http://nginx.org precise Release: 由於沒有公鑰,無法驗證下列簽名: NO_PUBKEY ABF5BD827BD9BF62
解決辦法:sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys ABF5BD827BD9BF62
3、重新執行:sudo apt-get update
sudo apt-get install nginx
出現如下錯誤:etting up nginx (1.6.3-1~precise) ...
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
invoke-rc.d: initscript nginx, action "start" failed.
原因:80端口被已經被其它進程使用。
解決辦法:更改nginx服務綁定端口爲88端口。sudo vi /etc/nginx/conf.d/default.conf
更改:server {
listen 88;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
4、啓動nginx
sudo /etc/init.d/nginx start
5、檢查nginx版本
nginx -v
6、配置php+mysql
sudo apt-get install php5-cli php5-cgi mysql-server php5-mysql
7、安裝FastCgi
sudo apt-get install spawn-fcgi
8、配置nginx
sudo vi /etc/nginx/conf.d/default.conf
location / {
root /usr/share/nginx/html;
index index.php index.html index.htm;#添加index.php
}
9、重啓nginx
sudo /etc/init.d/nginx restart
10、啓動fastcig php
spawn-fcgi -a 127.0.0.1 -p 9000 -C 10 -u nginx -f /usr/bin/php-cgi & #這裏注意:我第一次加了&才行,還不知道爲什麼
參數含義如下
* -f 指定調用FastCGI的進程的執行程序位置,根據系統上所裝的PHP的情況具體設置
* -a 綁定到地址addr
* -p 綁定到端口port
* -s 綁定到unix socket的路徑path
* -C 指定產生的FastCGI的進程數,默認爲5(僅用於PHP)
* -P指定產生的進程的PID文件路徑
* -u和-g FastCGI使用什麼身份(-u 用戶 -g 用戶組)運行,Ubuntu下可以使用www-data,其他的根據情況配置,如nobody、apache等現在可以在web根目錄下放個探針或php文件測試一下了
來源: <http://my.oschina.net/lht007/blog/112455>
11、加入開機啓動:
sudo vi /etc/rc.local
把/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 10 -u nginx -f /usr/bin/php-cgi 加到exit 0前。
12、no input file specified錯誤
sudo vi /etc/nginx/conf.d/default.conf
其中這個字段
location ~ .php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
include fastcgi_params;
}
注意
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
/usr/share/nginx/html 改爲你的網站根目錄,一般就是改成這個。
server 字段下root 目錄和網站根目錄保持一致
13、使用雅黑探針來探測web服務器:下載雅黑探針php文件—tz.php到/usr/share/nginx/html
#sudo chown ngixn tz.php
#sudo chmod u+rwz tz.php
通過瀏覽器輸入localhost:88/tz.php來查看web服務狀態。
14、 安裝discuz論壇
(1)在/usr/share/nginx/html下新建目錄bbs:#mdir bbs ,下載discuz X3.1版本discuz.zip並上傳到bbs中
(2)#sudo unzip discuz.zip
(3)#sudo chmod -R 777 discuz
(4)在瀏覽器中輸入localhost:88/bbs/upload/install,開始安裝論壇。