初識 Nginx(一)
阿新 • • 發佈:2018-12-24
1.什麼是Nginx
Nginx是一款高效能的http 伺服器/反向代理伺服器及電子郵件(IMAP/POP3)代理伺服器。由俄羅斯的程式設計師Igor Sysoev所開發,官方測試nginx能夠支支撐5萬併發連結,並且cpu、記憶體等資源消耗卻非常低,執行非常穩定
2.應用場景
1、http伺服器。Nginx是一個http服務可以獨立提供http服務。可以做網頁靜態伺服器。
2、虛擬主機。可以實現在一臺伺服器虛擬出多個網站。例如個人網站使用的虛擬主機。
3、反向代理,負載均衡。當網站的訪問量達到一定程度後,單臺伺服器不能滿足使用者的請求時,需要用多臺伺服器叢集可以使用nginx做反向代理。並且多臺伺服器可以平均分擔負載,不會因為某臺伺服器負載高宕機而某臺伺服器閒置的情況。
3.Nginx安裝
[[email protected] ~]# yum install -y pcre pcre-devel zlib zlib-devel openssl openssl-devel
[[email protected] ~]# tar -zxf nginx-1.8.0.tar.gz
[[email protected] ~]# cd nginx-1.8.0/
[[email protected] nginx-1.8.0]# ./configure \
>--prefix=/usr/local/nginx \
>--pid-path= /var/run/nginx/nginx.pid \
>--lock-path=/var/lock/nginx.lock \
>--error-log-path=/var/log/nginx/error.log \
>--http-log-path=/var/log/nginx/access.log \
>--with-http_gzip_static_module \
>--http-client-body-temp-path=/var/temp/nginx/client \
>--http-proxy-temp-path=/var/temp/nginx/proxy \
>--http-fastcgi-temp-path= /var/temp/nginx/fastcgi \
>--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
>--http-scgi-temp-path=/var/temp/nginx/scgi
注意:啟動nginx之前,上邊將臨時檔案目錄指定為/var/temp/nginx,需要在/var下建立temp及nginx目錄
[[email protected] nginx-1.8.0]# mkdir -p /var/temp/nginx/client
[[email protected] nginx-1.8.0]# make
[[email protected] nginx-1.8.0]# make install
編譯安裝完成後,就會安裝在/usr/local/nginx下
[email protected] nginx]# ll
總用量 12
drwxr-xr-x. 2 root root 4096 12月 3 18:14 conf
drwxr-xr-x. 2 root root 4096 12月 3 18:14 html
drwxr-xr-x. 2 root root 4096 12月 3 18:14 sbin
啟動nginx
[email protected] nginx]# cd sbin
[email protected] sbin]# ./nginx