Nginx ("engine x") 是一個高機能的 HTTP 和 反向署理 處事器,美國網站空間 香港網頁寄存,也是一個 IMAP/POP3/SMTP 署理處事器。 Nginx 是由 Igor Sysoev 為俄羅斯會見量第二的 Rambler.ru 站點開拓的,第一個果真版本0.1.0宣布于2004年10月4日。其將源代碼以類BSD許可證的形式宣布,因它的不變性、富厚的成果集、示例設置文件和低系統資源的耗損而聞名。2011年6月1日,nginx 1.0.4宣布。
一般我們都需要先裝pcre, zlib,前者為了重寫rewrite,后者為了gzip壓縮。
1.選定源碼目次
選定目次 /usr/local/
cd /usr/local/
安裝C++支持:yum install -y gcc-c++
2.安裝PCRE庫
cd /usr/local/
下載地點:pcre:http://sourceforge.net/projects/pcre/files/
wget http://sourceforge.net/projects/pcre/files/pcre/8.35/pcre-8.35.tar.gz/download
tar -zxvf pcre-8.21.tar.gz
cd pcre-8.21
./configure
make
make install
3.安裝zlib庫
cd /usr/local/
wget http://zlib.net/zlib-1.2.8.tar.gz
tar -zxvf zlib-1.2.8.tar.gz cd zlib-1.2.8
./configure
make
make install
4.安裝ssl
cd /usr/local/
wget http://www.openssl.org/source/openssl-1.0.1c.tar.gz
tar -zxvf openssl-1.0.1c.tar.gz
./config
make
make install
5.安裝nginx
Nginx 一般有兩個版本,別離是不變版和開拓版,您可以按照您的目標來選擇這兩個版本的個中一個,下面是把 Nginx 安裝到 /usr/local/nginx 目次下的具體步調:
cd /usr/local/
wget http://nginx.org/download/nginx-1.2.8.tar.gz
tar -zxvf nginx-1.2.8.tar.gz
cd nginx-1.2.8
./configure --prefix=/usr/local/nginx
make
make install
--with-pcre=/usr/src/pcre-8.21 指的是pcre-8.21 的源碼路徑。
--with-zlib=/usr/src/zlib-1.2.7 指的是zlib-1.2.7 的源碼路徑。
6.啟動
確保系統的 80 端口沒被其他措施占用,
/usr/local/nginx/sbin/nginx
查抄是否啟動樂成:
netstat -ano|grep 80 有功效輸入說明啟動樂成
打開欣賞器會見此呆板的 IP,假如欣賞器呈現 Welcome to nginx! 則暗示 Nginx 已經安裝并運行樂成。
7.重啟
/usr/local/nginx/sbin/nginx -s reload
8.修改設置文件
cd /usr/local/nginx/conf
vi nginx.conf
9.常用設置
#nginx運行用戶和組
user www www;
#啟動歷程,凡是配置成和cpu的數量相等
worker_processes 4;
#全局錯誤日志及PID文件
pid /var/run/nginx.pid;
error_log /var/log/nginx/error.log;
events {
#epoll是多路復用IO(I/O Multiplexing)中的一種方法,可是僅用于linux2.6以上內核,可以大大提高nginx的機能
use epoll;
#單個靠山worker process歷程的最大并發鏈接數
worker_connections 10240;
}
#設定http處事器,操作它的反向署理成果提供負載平衡支持
http {
include mime.types;
default_type application/octet-stream;
error_page 400 403 500 502 503 504 /50x.html;
index index.html index.shtml
autoindex off;
fastcgi_intercept_errors on;
sendfile on;
# These are good default values.
tcp_nopush on;
tcp_nodelay off;
# output compression saves bandwidth
gzip off;
#gzip_static on;
#gzip_min_length 1k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_buffers 4 16k;
gzip_proxied any;
gzip_disable "MSIE [1-6]\.";
gzip_types text/plain text/html text/css application/x-javascript application/xml application/xml+rss text/javascript;
#gzip_vary on;
server_name_in_redirect off;
#設定負載平衡的處事器列表
upstream portals {
server 172.16.68.134:8082 max_fails=2 fail_timeout=30s;
server 172.16.68.135:8082 max_fails=2 fail_timeout=30s;