### nginx在ubuntu上的安裝
1、安裝Nginx
```
apt-get install nginx
```
(要最新版本下載下來編譯吧)
裝完應該能正常運行了。如果之前有裝APACHE要改下端口。。。或者直接
```
apt-get remove apache2
/etc/init.d/nginx stop
/etc/init.d/nginx start
```
2、安裝php-cgi
```
apt-get install php-cgi
```
(要自定義安裝的編譯吧)
3、改php-cgi的配置
Ubuntu下是/etc/php5/cgi/php.ini
之前有安裝過php的話會復制apache的配置文件
打開cgi.fix_pathinfo選項:
```
cgi.fix_pathinfo=1;
```
4、改Nginx的fastcgi傳遞參數
Ubuntu下是/etc/nginx/fastcgi_params
默認應該已經設置好了,內容差不多就下面那樣:
**代碼:**
```
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
# PHP only, required if PHP was built with –enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
```
5、創建VHost配置(這里只說Ubuntu下的,也就路徑和包含文件目錄的區別了)
在/etc/nginx/sites-available/下創建服務器配置文件比如myserver
```
ln -n /etc/nginx/sites-available/myserver /etc/nginx/sites-enabled/myserver
```
其實懶的話直接創建在enabled里也沒問題-。-
內容填:
**代碼:**
```
server {
listen 80;
server_name myserver.com;
access_log /var/log/nginx/myserver.access.log;location / {
root /wwwroot/myserver;
index index.php;
autoindex off;
}
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME /wwwroot/myserver/$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
}
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/nginx-default;
}
# deny access to .htaccess files, if Apache’s document root
location ~ /\.ht {
deny all;
}
}
```
6、安裝spawn-fcgi
下載可到這里,這東西已經獨立出來了
[http://redmine.lighttpd.net/projects/spawn-fcgi/wiki](http://redmine.lighttpd.net/projects/spawn-fcgi/wiki)
下完后解壓編譯
```
sudo ./configure –prefix=/usr/local
sudo make
sudo make install
```
7、啟動spaw-fcgi
```
sudo spawn-fcgi -a 127.0.0.1 -p 9000 -u www-data -g www-data -f /usr/bin/php5-cgi -F 10
```
哦,對后面10進程不爽的人可以取消或是加到100
8、重啟Nginx
```
/etc/init.d/nginx restart
```
9、定義下hosts就可以看結果啦
編輯/etc/hosts加入
```
127.0.0.1 myserver.com
```
然后打開瀏覽器就可以看結果啦~
有問題歡迎指出~~
- 主要文檔
- Nginx功能概述
- 為什么選擇Nginx
- Nginx安裝
- 運行和控制Nginx
- 配置符號參考
- 優化 Nginx
- 常見問題(FAQ)
- 調試 nginx
- 核心模塊
- Nginx主模塊
- Nginx事件模塊
- 基本模塊
- http核心模塊
- HttpIndex模塊
- HttpAccess模塊
- HttpAuthBasic模塊
- HttpAutoindex模塊
- Browser模塊
- Charset模塊
- HttpEmptyGif模塊
- HttpFcgi模塊
- Geo模塊
- HttpGzip模塊
- HttpHeaders模塊
- HttpIndex模塊
- HttpReferer模塊
- HttpLimit zone
- HttpLimitReqest模塊
- HttpLog模塊
- map
- Memcached
- HttpProxy模塊
- HttpRewrite模塊
- HttpSSI模塊
- HttpUserId
- 其他模塊
- Addition模塊
- EmbeddedPerl
- flv
- HttpGzipStatic
- RandomIndex
- HttpGeoIP
- HttpRealIp
- HttpSSL
- StubStatus模塊
- HttpSubstitution
- HttpDav模塊
- GooglePerftools
- HttpXSLT
- HttpSecureLink
- HttpImageFilter
- mail模塊
- MailCore
- MailAuth
- MailProxy
- MailSSL
- 安裝
- nginx在windows上的安裝
- nginx在freebsd上的安裝
- nginx在ubuntu上的安裝
- nginx在fedora上的安裝
- nginx php-fpm安裝配置
- 配置示例和方法
- 完整例子
- 完整例子2
- 虛擬主機
- 負載均衡
- nginx防盜鏈
- HWLoadbalancerCheckErrors