### nginx在freebsd上的安裝
一 . 安裝必備軟件 MySQL+PHP+Pcre
```
cd /usr/ports/database/mysql50-server && make install clean
cd /usr/lang/php5/ && make install clean ??選擇對cgi mysql等的支持
cd /usr/devel/pcre && make install clean
```
用ports安裝 /usr/ports/www/nginx, make install clean
二、弄了一個fastcgi的腳本,來自lighttpd
1) cd /usr/ports/www/lighttpd
2) make
3) cp /usr/ports/www/lighttpd/work/lighttpd-1.4.18/src/spawn-cgi /usr/bin
4) make clean
三、修改配置文件:
1,/usr/local/etc/nginx/nginx.conf:
```
user www www;
worker_processes 10;
error_log /usr/local/etc/nginx/logs/nginx_error.log crit;
worker_rlimit_nofile 51200;
events
{
??use epoll;
??worker_connections 51200;
}
http
{
??include ??conf/mime.types;
??default_type application/octet-stream;
??charset gb2312;
??server_names_hash_bucket_size 128;
??keepalive_timeout 60;
??tcp_nodelay on;
??gzip on;
??gzip_min_length 1k;
??gzip_buffers ??4 8k;
??gzip_http_version 1.1;
??gzip_types ??text/plain application/x-javascript. text/css text/html application/xml;
??server
??{
??listen ??80;
??server_name www.test.com;
??index index.html index.htm index.php;
??root /usr/local/www/data/;
??location ~ .*\.php?$
??{
??include fcgi.conf;
??fastcgi_pass 127.0.0.1:9000;
??fastcgi_index index.php;
??}
??log_format access '$remote_addr - $remote_user [$time_local] "$request" '
??'$status $body_bytes_sent "$http_referer" '
??'"$http_user_agent" $http_x_forwarded_for';
??access_log /usr/local/nginx/logs/access.log access;
??}
??}
```
2 ,先將php.ini的配置中 cgi.fix_pathinfo=1 這樣php-cgi方能正常使用SCRIPT_FILENAME這個變量。
3,編輯fcgi.conf文件,加入
```
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE ??nginx;
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_FILENAME ??$document_root$fastcgi_script_name;
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 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;
```
四,啟動
1, 啟動fcgi
```
/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u www -f /usr/local/bin/php-cgi
```
參數說明:
-f <fcgiapp> 指定調用FastCGI的進程的執行程序位置,根據系統上所裝的PHP的情況具體設置
-a <addr> 綁定到地址addr
-p <port> 綁定到端口port
-s <path> 綁定到unix socket的路徑path
-C <childs> 指定產生的FastCGI的進程數,默認為5(僅用于PHP)
-P <path> 指定產生的進程的PID文件路徑
-u和-g FastCGI使用什么身份(-u 用戶 -g 用戶組)運行,Ubuntu下可以使用www-data,其他的根據情況配置,如nobody、apache等
也可建立腳本
1) `ee /usr/bin/php-fastcgi`
```
#!/bin/sh
/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u www -f /usr/local/bin/php-cgi
```
2) c`hmod 755 /usr/bin/php-fastcgi `
3) `ee /usr/local/etc/rc.d/init-fastcgi `
????
```
#!/bin/bash
PHP_SCRIPT=/usr/bin/php-fastcgi
RETVAL=0
case "$1" in
start)
$PHP_SCRIPT
RETVAL=$?
;;
stop)
killall -9 php
RETVAL=$?
;;
restart)
killall -9 php
$PHP_SCRIPT
RETVAL=$?
;;
*)
echo "Usage: php-fastcgi {start|stop|restart}"
exit 1
;;
esac
exit $RETVAL
```
4) `chmod 755 /usr/local/etc/rc.d/init-fastcgi `
2,啟動nginx
nginx -t -c /usr/local/etc/nginx/nginx.conf ??測試配置是否正確
如果屏幕顯示以下兩行信息,說明配置文件正確:
```
the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
the configuration file /usr/local/etc/nginx/nginx.conf was tested successfully
```
啟動:
```
nginx -c /usr/local/etc/nginx/nginx.conf
```
開機自動啟動加入/etc/rc.conf
```
nginx_enable="YES"
```
**nginx參數:
**
**-c </path/to/config>**為 Nginx 指定一個配置文件,來代替缺省的。
**-t**不運行,而僅僅測試配置文件。nginx 將檢查配置文件的語法的正確性,并嘗試打開配置文件中所引用到的文件。
**-v**顯示 nginx 的版本。
**-V**顯示 nginx 的版本,編譯器版本和配置參數。
- 主要文檔
- 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