標籤:nginx web
Nginx
1. 高效能的HTTP Server,支援高達20000並發訪問
2. 反向 Proxy伺服器,給網站加速
3. 做為前端一個負載平衡器
========================================================
一、準備工作
# service httpd stop
# chkconfig httpd off
所需的軟體: 開發庫,openssl-devel
二、部署Nginx
1. pcre: 支援Regex,地址修正rewrite
# tar zxf pcre-8.31.tar.gz
# cd pcre-8.31
# ./configure && make && make install
# ldconfig
2. nginx
# useradd www
# tar xvf nginx-1.2.2.tar.gz
# cd nginx-1.2.2
[[email protected] nginx-1.2.2]# ./configure \
> --user=www \
> --group=www \
> --prefix=/usr/local/nginx-1.2.2 \
> --with-http_stub_status_module \
> --with-http_sub_module \
> --with-http_ssl_module \
> --with-pcre=/usr/src/pcre-8.31 #pcre來源程式目錄
#--with-pcre=/usr/src/pcre-8.31 指的是pcre-8.31 的源碼路徑。
#--with-zlib=/usr/src/zlib-1.2.7 指的是zlib-1.2.7 的源碼路徑。
# make && make install
# ln -s /usr/local/nginx-1.2.2/ /usr/local/nginx
# tree /usr/local/nginx/
/usr/local/nginx/
|-- conf
| |-- fastcgi.conf
| |-- fastcgi.conf.default
| |-- fastcgi_params
| |-- fastcgi_params.default
| |-- koi-utf
| |-- koi-win
| |-- mime.types
| |-- mime.types.default
| |-- nginx.conf //主設定檔
| |-- nginx.conf.default
| |-- scgi_params
| |-- scgi_params.default
| |-- uwsgi_params
| |-- uwsgi_params.default
| `-- win-utf
|-- html
| |-- 50x.html
| `-- index.html
|-- logs
`-- sbin
`-- nginx
3. 啟動
[[email protected] ~]# /usr/local/nginx/sbin/nginx
[[email protected] ~]# netstat -tnlp |grep :80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 10627/nginx
4. 測試
# links -dump 192.168.9.110
Welcome to nginx!
# echo "/usr/local/nginx/sbin/nginx" >> /etc/rc.local #開機運行
二、Nginx基本配置
[[email protected] ~]# vim /usr/local/nginx/conf/nginx.conf
CoreModule Nginx核心模組
EventsModule 事件驅動模組
HttpCoreModule http核心模組
# sed -i ‘/^[ \t]*#/d;/^[ \t]*$/d‘ /usr/local/nginx/conf/nginx.conf
# vim /usr/local/nginx/conf/nginx.conf
worker_processes 2; #初始啟動的進程數(建議CPU的core數)
worker_connections 15000; #最大串連數
server {
listen 80; #監聽的連接埠
server_name localhost; #網站名稱
location / {
root html; #root指令指定網站主目錄(相對於nginx的安裝目錄)
index index.html index.htm; #預設首頁
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
語法檢查:
# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
重新載入nginx:
[[email protected] ~]# pgrep nginx
5693
5757
[[email protected] ~]# kill -HUP 5693
[[email protected] ~]# pgrep nginx
5693
5787
# /usr/local/nginx/sbin/nginx -s reload
# /usr/local/nginx/html/ #網站預設主目錄
# echo "Welcome to Jeffery Nginx" > /usr/local/nginx/html/index.html
[[email protected] ~]# elinks -dump 192.168.9.110
Welcome to Jeffery Nginx
========================================================
排錯:
[[email protected] ~]# /usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx: error while loading shared libraries: libpcre.so.1: cannot
open shared object file: No such file or directory
編譯nginx指定 --with-pcre=/usr/src/pcre-8.31 指定pcre-8.31 的源碼路徑。
========================================================
本文出自 “Jeffery Blog” 部落格,請務必保留此出處http://oceanszf.blog.51cto.com/6268931/1539137