Nginx Web 服務應用入門(1)

1. Nginx 服務概述html

1.1 Nginx 服務簡介前端

        Nginx 是一個開源的,支持高性能、高併發的 WWW 服務和代理服務軟件,它是由俄羅斯人 Igor Sysoev 開發的。Nginx 因具備高併發(特別是靜態資源)、佔用系統資源少等特性,且功能豐富而逐漸流行起來。linux

1.2 Nginx HTTP 服務器特點及優勢nginx

① 支持高併發:能支持幾萬併發鏈接(特別是靜態小文件業務環境);vim

② 資源消耗少:在 3 萬併發鏈接下,開啓 10 個 Nginx 線程消耗的內存不到 200M ;windows

③ 能夠作 HTTP 反向代理,即負載均衡功能,內置對 RS 節點服務器健康檢查功能,這至關於專業的 Haproxy 軟件或 LVS 功能;後端

④ 具有 Squid 等專業緩存軟件等的緩存功能;瀏覽器

⑤ 支持異步網絡 I/O 事件模型 epoll 。緩存

1.3 Nginx 軟件的主要企業功能應用安全

① 做爲 Web 服務軟件;

② 反向代理或負載均衡服務;

③ 前端業務數據緩存服務;

提示:Nginx 的以上三大功能是國內使用 Nginx 的主要場景,特別是前兩個。

1.4 Nginx Web 服務介紹

        Nginx 安裝簡單,配置文件簡潔,並且配置靈活。近兩年來,Nginx 在國內互聯網領域的使用日趨火熱,愈來愈多的網絡開始使用,如淘寶、阿里、京東、小米、網易、新浪、趕集網等。

1.5 Nginx 做爲 Web 服務器的主要應用場景

① 使用 Nginx 運行 HTML、JS、CSS、小圖片等靜態數據(此功能相似 Lighttpd 軟件);

② Nginx 結合 FastCGI 運行 PHP 等動態程序(例如使用 fastcgi_pass 方式);

③ Nginx 結合 Tomcat/Resin 等支持 Java 動態程序(經常使用 proxy_pass 方式)。

1.6 Nginx 軟件的特色

① 基於異步網絡 I/O 模型(epoll、kqueue);

② 具有支持高性能,高併發的特性,併發鏈接可達數萬;

③ 對小文件(小於 1M 的靜態文件)高併發支持很好,性能很高;

④ 不支持相似 Apache 的 DSO 模式,擴展庫必須編譯進主程序(缺點);

⑤ 進程佔用資源比較低;

⑥ 支持 Web 、反向 Proxy、Cache 三大重點功能,而且都很優秀;

⑦ 市場份額在逐年快速增加。

1.7 Lighttpd 的特色

① 基於異步網絡 I/O 模型,性能、併發都與 Nginx 相近;

② 擴展庫是 SO 模式,比 Nginx 靈活;

③ 目前國內的使用率比較低,安全性沒有 Apache 和 Nginx 好;

④ 經過插件(mod_secdownload)可實現文件 URL 地址加密(優勢);

⑤ 社區不靈活,市場份額較低。

1.8 爲何 Nginx 整體性能比 Apache 高

          Nginx 使用最新的 epoll (Linux 2.6 內核)和 kqueue (freebsd)異步網絡 I/O 模型;Apache 使用的是傳統的 select 模型。

提示:目前 Linux 下可以承受高併發訪問的 Squid、Memcached 軟件採用的都是 epoll 模型。

1.9 Apache select 和 Nginx epoll 的技術對比以下表

        指標        

       select

       epoll

        性能

 隨鏈接數增長性能急劇降低

鏈接數增長性能不降

      鏈接數

限制鏈接數不超過1024,不然要改配置。

鏈接數無限制

 內在處理機制

線性輪詢

回調 callback

   開發複雜性

 

 

 

 

 

 

 

 

 

 

 

 

2. 企業中如何正確選擇 Web 服務

① 靜態業務:如果高併發場景,儘可能採用 Nginx 或 Lighttpd ,兩者首選 Nginx ;

② 動態業務:理論上採用 Nginx 和 Apache 都可,建議選擇 Nginx ,爲了不相同業務的服務軟件多樣化,增長額外維護成本。動態業務能夠由 Nginx 兼作前端代理,再根據頁面元素的類型或目錄,轉發到後端相應的服務器進行處理。

③ 既有靜態業務又有動態業務:採用 Nginx 。

切記:在知足需求的前提下選擇本身最擅長的軟件避免給企業帶來災難性的損失。

3. 基於 CentOS 6.8 安裝 Nginx 服務

3.1 檢查並安裝 Nginx 基礎依賴包

[root@lnmp02 ~]# rpm -qa pcre pcre-devel

pcre-7.8-7.el6.x86_64    #  pcre 包已經存在。

[root@lnmp02 ~]# yum install pcre-devel -y    # 安裝 pcre-devel 包。

[root@lnmp02 ~]# yum install openssl-devel -y    # 安裝 openssl-devel 包。

[root@lnmp02 tools]# rpm -qa pcre pcre-devel openssl openssl-devel    # 檢查依賴包。

openssl-devel-1.0.1e-57.el6.x86_64

pcre-7.8-7.el6.x86_64

openssl-1.0.1e-57.el6.x86_64

pcre-devel-7.8-7.el6.x86_64

3.2 建立 Nginx 服務的用戶

[root@lnmp02 nginx-1.6.3]# useradd nginx -s /sbin/nologin -M

[root@lnmp02 nginx-1.6.3]# id nginx

uid=501(nginx) gid=501(nginx) groups=501(nginx)

3.3 安裝 Nginx 服務

[root@lnmp02 ~]# rpm -qa nginx   #  查看是否已經安裝。

[root@lnmp02 ~]# mkdir -p  /home/oldboy/tools   #  建立安裝目錄。

[root@lnmp02 ~]# cd /home/oldboy/tools   

[root@lnmp02 tools]# wget -q http://nginx.org/download/nginx-1.6.3.tar.gz   #  下載軟件包。

[root@lnmp02 tools]# ls nginx-1.6.3.tar.gz   #  查看下載的軟件包。

nginx-1.6.3.tar.gz

[root@lnmp02 tools]# ls nginx-1.6.3.tar.gz -lk     #  查看下載的軟件包(787 K)。

-rw-r--r-- 1 root root 787 Apr  8  2015 nginx-1.6.3.tar.gz

[root@lnmp02 tools]# tar xf nginx-1.6.3.tar.gz   #  解壓下載的軟件包。

[root@lnmp02 tools]# cd nginx-1.6.3

[root@lnmp02 nginx-1.6.3]# ls   #  查看該軟件內容。

auto     CHANGES.ru  configure  html     man     src

CHANGES  conf        contrib    LICENSE  README

[root@lnmp02 nginx-1.6.3]# tree|wc -l    #  一共 404 行。

404

[root@lnmp02 nginx-1.6.3]# ./configure --prefix=/application/nginx-1.6.3 --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module  

#  編譯軟件(可以使用 ./configure --help 查看相關幫助信息)。

[root@lnmp02 nginx-1.6.3]# echo $?  

0

[root@lnmp02 nginx-1.6.3]# make

[root@lnmp02 nginx-1.6.3]# make install    #  安裝。

[root@lnmp02 nginx-1.6.3]# cd ..

[root@lnmp02 tools]# ll  -ld /application/nginx-1.6.3/

drwxr-xr-x 6 root root 4096 Dec 18 22:40 /application/nginx-1.6.3/

[root@lnmp02 tools]# ln -s /application/nginx-1.6.3/ /application/nginx

#  建立軟連接(方便使用、更新時只需重建軟連接、引用該軟連接的地方無需改動)。

[root@lnmp02 tools]# ls -l /application/

total 4

lrwxrwxrwx 1 root root   25 Dec 18 22:44 nginx -> /application/nginx-1.6.3/

drwxr-xr-x 6 root root 4096 Dec 18 22:40 nginx-1.6.3

[root@lnmp02 tools]# /application/nginx/sbin/nginx    #  啓動 Nginx 服務。

[root@lnmp02 tools]# ss -lntup|grep nginx   #  查看 Nginx 服務的端口。

tcp    LISTEN     0   128  *:80      *:*    users:(("nginx",4154,6),("nginx",4155,6))

3.4 啓動命令詳解

3.4.1 參數說明

[root@lnmp02 conf]# /application/nginx/sbin/nginx -h

Options:

  -?,-h     : this help

  -v         : show version and exit

  -V         : show version and configure options then exit     #  查看編譯的參數。

  -t          : test configuration and exit     #  檢查語法。

  -q            : suppress non-error messages during configuration testing

  -s signal     : send signal to a master process: stop, quit, reopen, reload     #  指定信號處理。

  -p prefix     : set prefix path (default: /application/nginx-1.6.3/)

  -c filename   : set configuration file (default: conf/nginx.conf)     #  指定配置文件。

  -g directives : set global directives out of configuration file

3.4.2 啓動(或重啓)Nginx 前要檢查語法:

提示:避免配置文件出錯,網站打不開的狀況,工做中會寫腳本,reload 後調用腳本批量檢查語法,不正常就自動還原(發佈代碼相關)

[root@lnmp02 conf]# /application/nginx/sbin/nginx -t

nginx: the configuration file /application/nginx-1.6.3/conf/nginx.conf syntax is ok

nginx: configuration file /application/nginx-1.6.3/conf/nginx.conf test is successful

3.5 啓動 Nginx 並訪問測試

經過 widows 瀏覽器訪問 Ngnix 服務器的 IP:192.168.136.143 ,結果以下圖所示:

 

提示:若是不成功,到 widows 做以下操做:

① ping 192.168.136.143

② telnet 192.168.136.143 80   #  若是此路不通,關閉 Ngnix 服務器防火牆。

3.6 查看 Nginx 編譯的參數

[root@lnmp02 tools]# /application/nginx/sbin/nginx -V

nginx version: nginx/1.6.3

built by gcc 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC)

TLS SNI support enabled

configure arguments: --prefix=/application/nginx-1.6.3 --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module

3.7 Nginx 故障排查:

① Selinux 是否關閉;

② 防火牆是否關閉;

③ 經過查看日誌排錯:

     cat /var/log/message

     cat /application/nginx/logs/error.log

4. 瞭解 Nginx 服務

4.1 Nginx 安裝目錄下文件詳情

[root@lnmp02 tools]# cd /application/nginx

[root@lnmp02 nginx]# ll

total 36

drwx------ 2 nginx root 4096 Dec 18 22:59 client_body_temp

drwxr-xr-x 2 root  root 4096 Dec 18 22:40 conf

drwx------ 2 nginx root 4096 Dec 18 22:59 fastcgi_temp

drwxr-xr-x 2 root  root 4096 Dec 18 22:40 html

drwxr-xr-x 2 root  root 4096 Dec 18 22:59 logs

drwx------ 2 nginx root 4096 Dec 18 22:59 proxy_temp

drwxr-xr-x 2 root  root 4096 Dec 18 22:40 sbin

drwx------ 2 nginx root 4096 Dec 18 22:59 scgi_temp

drwx------ 2 nginx root 4096 Dec 18 22:59 uwsgi_temp

[root@lnmp02 nginx]# ls -l|grep -v temp   #  排除帶有 temp 的臨時文件。

total 36

drwxr-xr-x 2 root  root 4096 Dec 18 22:40 conf   # 配置文件。

drwxr-xr-x 2 root  root 4096 Dec 18 22:40 html   # Nginx 的默認網站(站點)目錄。

drwxr-xr-x 2 root  root 4096 Dec 18 22:59 logs   # 訪問日誌、錯誤日誌、進程號(pid)等。

drwxr-xr-x 2 root  root 4096 Dec 18 22:40 sbin   # 該目錄下是啓動命令。

4.2 Nginx 默認站點目錄

[root@lnmp02 nginx]# cd html

[root@lnmp02 html]# ls -l

total 8

-rw-r--r-- 1 root root 537 Dec 18 22:40 50x.html

-rw-r--r-- 1 root root 612 Dec 18 22:40 index.html   #  站點的首頁文件(Welcoe to Nginx !)

4.3 Nginx 的配置文件

[root@lnmp02 nginx]# cd conf/

[root@lnmp02 conf]# ls -l nginx.conf   #  Nginx 的核心配置文件。

-rw-r--r-- 1 root root 2656 Dec 18 22:40 nginx.conf

4.4 Nginx 經常使用模塊介紹

可經過官方地址 http://nginx.org/en/docs/ 查看

① Nginx 核心功能模塊:【Core functionality】

Nginx 核心功能模塊負責 Nginx 的全局應用,主要對應主配置文件的 Main 區塊和 Events 區塊區域,這裏有不少 Nginx 必須的全局參數配置。

② 標準的 HTTP 功能模塊集合:

這些標準的 HTTP 功能模塊,雖然不是 Nginx 軟件所必須的,但都是很經常使用的,所以絕大部分默認狀況都會自動安裝到 Nginx 軟件中(見 P157 表 5-2),在生產環境中,配置、調整以及優化 Nginx 軟件,主要就是根據這些模塊的功能修改相應的參數來實現的。

4.5 Nginx 的目錄結構說明        

[root@lnmp02 ~]# tree /application/nginx

/application/nginx

├── client_body_temp

├── conf                                 # Nginx 全部配置文件的目錄。(重要)

│   ├── fastcgi.conf                 # fastcgi 相關參數的配置文件。      

│   ├── fastcgi.conf.default     # 上面的原始備份。

│   ├── fastcgi_params

│   ├── fastcgi_params.default

│   ├── koi-utf

│   ├── koi-win   

│   ├── mime.types                  # 媒體類型。

│   ├── mime.types.default

│   ├── nginx.conf                   #  Nginx 默認的主配置文件。

│   ├── nginx.conf.default

│   ├── scgi_params

│   ├── scgi_params.default

│   ├── uwsgi_params

│   ├── uwsgi_params.default

│   └── win-utf

├── fastcgi_temp                       # fastcgi 臨時數據目錄。

├── html                                   # 編譯安裝時 Nginx 的默認站點目錄。

│   ├── 50x.html                        # 錯誤頁面優雅替代顯示文件。

│   └── index.html                    # 默認的首頁文件。,首頁文件名字是在 nginx.conf 中事先定義好的。(在實際工做中習慣用 index.html  index.pgp  index.jsp 來作網站的首頁文件)

├── logs                                     # Nginx 默認的日誌路徑。

│   ├── access.log                      # Nginx 默認訪問日誌文件(可經過命令:tail -f access.log 實時觀看網站用戶訪問狀況信息)

│   └── error.log                        # Nginx 的錯誒日誌文件,出現啓動故障等問題查看該錯誤日誌。

│   └── nginx.pid                       # Nginx 的進程號。

├── proxy_temp                        # 臨時目錄。

├── sbin                                     # Nginx 命令的目錄,如啓動命令:nginx 。

│   └── nginx                             # Nginx 的啓動命令:nginx 。

├── scgi_temp                           # 臨時目錄。

└── uwsgi_temp                        # 臨時目錄。

9 directories, 20 files

提示:全部結尾爲 default 的文件都是備份文件。

4.6 Nginx 配置文件模板詳解

[root@lnmp02 ~]# cd /application/nginx/conf/

[root@lnmp02 conf]# egrep -v "#|^$" nginx.conf.default  # 過濾掉註釋和空行查看文件。

worker_processes  1;                                 # worker 進程的數量。(通常認爲和 CPU 核數相等)     

events {                                                        # 事件區塊開始。

    worker_connections  1024;                   # 每一個 worker 進程支持的最大鏈接數。

}                                                                   # 事件區塊結束。

http {                                                            # http 區塊開始。

    include       mime.types;                           # Nginx 支持的媒體類型庫文件。

    default_type  application/octet-stream;   # 默認的媒體類型。

    sendfile        on;                                         # 開啓高效傳輸模式。

    keepalive_timeout  65;                               # 鏈接超時,

    server {                                                       # 第一個 server 區塊開始。

        listen       80;                                           # 提供服務的端口,默認爲 80 。

        server_name  localhost;                         # 提供服務的域名主機名。

        location / {                                             # 第一個 location 區塊開始。

            root   html;                                         # 站點的根目錄。

            index  index.html index.htm;             # 默認的首頁文件,多個用空格隔開。

        }                                                               # 第一個 location 區塊結束。

        error_page 500 502 503 504  /50x.html;# 出現對應的 http 狀態碼時,使用 50x.html 迴應客戶。

        location = /50x.html {                              # location 區塊開始,訪問 50x.html 。  

            root   html;                                           # 指定對應的站點目錄爲 html 。

        }

    }    

}                                                                 # http 區塊結束。 

5. Nginx 虛擬主機

5.1 虛擬主機概念

        所謂虛擬主機,在 Web 服務裏就是一個獨立的網站站點,這個站點對應獨立的域名(也但是 IP 或端口)具備獨立的程序及資源目錄,能夠獨立地對外提供服務供用戶訪問。這個獨立的站點在配置裏是由必定格式的標籤段標記的。Nginx 軟件使用一個 server{} 標籤來表示一個虛擬主機。一個 Web 服務裏能夠有多個虛擬主機標籤對,便可以同時支持多個虛擬主機站點。

5.2 虛擬主機類型

① 基於域名的虛擬主機;★★★★★

② 基於端口的虛擬主機;★★

③ 基於 I P 的虛擬主機。

5.3 搭建兩個基於域名的虛擬主機

[root@lnmp02 conf]# /application/nginx/sbin/nginx       # 啓動 Nginx 服務。

[root@lnmp02 conf]# egrep -v "#|^$" nginx.conf.default >nginx.con  #  最小化編輯 conf 文件。

[root@lnmp02 conf]# vim nginx.conf

[root@lnmp02 conf]# cat nginx.conf

worker_processes  1;

events {

    worker_connections  1024;

}

http {

    include       mime.types;

    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65;

    server {

        listen       80;

        server_name  www.etiantian.org;

        location / {

            root   html/www;

            index  index.html index.htm;

        }

    }

    server {

        listen       80;

        server_name  bbs.etiantian.org;

        location / {

            root   html/bbs;

            index  index.html index.htm;

        }

    }

}

[root@lnmp02 conf]# mkdir ../html/{www,bbs} -p   #  建立兩個站點目錄。

[root@lnmp02 conf]# tree ../html/

../html/

├── 50x.html

├── bbs

├── index.html

└── www

[root@lnmp02 conf]# echo "www.etiantian.org" > ../html/www/index.html

[root@lnmp02 conf]# echo "bbs.etiantian.org" > ../html/bbs/index.html   

#  上面兩行意爲在首頁文件配置以上內容便於訪問測試時分辨。

[root@lnmp02 conf]# cat ../html/{www,bbs}/index.html    #  查看設置的訪問首頁內容。

www.etiantian.org

bbs.etiantian.org

[root@lnmp02 conf]# /application/nginx/sbin/nginx -t    #  檢查語法。

[root@lnmp02 conf]# /application/nginx/sbin/nginx -s reload   #  從新加載讓配置生效。

[root@lnmp02 conf]# vi /etc/hosts   #  編輯 hosts 作 DNS 解析。

192.168.136.143 www.etiantian.org bbs.etiantian.org  

5.4 Linux 本地作 DNS 解析並訪問

在 Linux 客戶端本地經過編輯 hosts 作 DNS 解析:

工做中在購買的 DNS 解析頁面以 A 記錄的形式解析到公網 IP 便可。

在 Linux 客戶端本地訪問結果:

[root@lnmp02 conf]# ping www.etiantian.org

[root@lnmp02 conf]# ping bbs.etiantian.org

[root@lnmp02 conf]# curl www.etiantian.org

www.etiantian.org

[root@lnmp02 conf]# curl bbs.etiantian.org

bbs.etiantian.org

提示:能 ping 通而且 curl 返回設置的首頁內容表示配置成功!

5.5 在 Windows 作 DNS 解析後訪問

在 Windows 的 /etc/hosts 下經過編輯 hosts 作 DNS 解析:

徽標鍵+R 調出運行窗口輸入 drivers:

把內容:192.168.136.143 www.etiantian.org bbs.etiantian.org  拖入hosts 文件。

提示:若是不能修改 hosts 文件就讓記事本以管理員身份運行再修改 hosts 文件。

在  Windows 訪問配置的基於域名的虛擬主機結果:

在 windows 訪問上面兩個域名可看到訪問首頁內容(返回設置的 index.html)。【略】

若是在 windows 訪問該服務器的 IP 地址,會返回 www.etiantian.org (第一個)。

5.6 Nginx 配置虛擬主機步驟小結

① 增長一個完整的 server 標籤段到結尾處(注意要放在 http 的結束大括號前,也就是將 server 標籤段放入 http 標籤);

② 更改 server_name 及對應網頁的 root 根目錄,若是須要其它參數,能夠增長或修改;

③ 建立 server_name 域名對應網頁的根目錄,而且創建測試文件,若是沒有 index.html 首頁,訪問會出現 403 錯誤;

④ 檢查 Nginx 配置文件語法,平滑重啓 Nginx 服務,快速檢查啓動結果;

⑤ 在客戶端對 server_name 處配置的域名作 host 解析或 DNS 配置,並檢查(ping、telenet);

⑥ 在 Windows 瀏覽器中輸入地址訪問,或在 Linux 客戶端作 hosts 解析,用 wget 或 curl 接配置的域名作訪問測試是否成功。

6.  利用 include 功能優化 Nginx 的配置文件

[root@lnmp02 ~]# /application/nginx/sbin/nginx     # 啓動 Nginx 服務。

[root@lnmp02 ~]# cd /application/nginx/conf/

[root@lnmp02 ~]# cp nginx.conf nginx.conf.base_name   # 備份配置文件。

[root@lnmp02 conf]# vim nginx.conf     #  編輯配置文件。

[root@lnmp02 conf]# cat nginx.conf

worker_processes  1;

events {

    worker_connections  1024;

}

http {

    include       mime.types;

    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65;

    # nginx vhosts config

    include extra/www.conf;

    include extra/bbs.conf;

    include extra/blog.conf;

}

[root@lnmp02 conf]# mkdir extra   #  建立目錄extre 。     

[root@lnmp02 conf]# cat -n  nginx.conf.base_name    # 帶行號輸出域名虛擬主機的備份文件。          

     1  worker_processes  1;

     2  events {

     3      worker_connections  1024;

     4  }

     5  http {

     6      include       mime.types;

     7      default_type  application/octet-stream;

     8      sendfile        on;

     9      keepalive_timeout  65;

    10      server {

    11          listen       80;

    12          server_name  www.etiantian.org;

    13          location / {

    14              root   html/www;

    15              index  index.html index.htm;

    16          }

    17      }

    18      server {

    19          listen       80;

    20          server_name  bbs.etiantian.org;

    21          location / {

    22              root   html/bbs;

    23              index  index.html index.htm;

    24          }

    25      }

    26      server {

    27          listen       80;

    28          server_name  blog.etiantian.org;

    29          location / {

    30              root   html/blog;

    31              index  index.html index.htm;

    32          }

    33      }

    34  }

[root@lnmp02 conf]# sed -n '10,17p' nginx.conf.base_name    #  取出第一個 server 標籤。

    server {

        listen       80;

        server_name  www.etiantian.org;

        location / {

            root   html/www;

            index  index.html index.htm;

        }

    }

[root@lnmp02 conf]# sed -n '10,17p' nginx.conf.base_name >extra/www.conf  # 放入指定目錄 extra

[root@lnmp02 conf]# sed -n '18,25p' nginx.conf.base_name     #  取出第二個 server 標籤。

    server {

        listen       80;

        server_name  bbs.etiantian.org;

        location / {

            root   html/bbs;

            index  index.html index.htm;

        }

    }

[root@lnmp02 conf]# sed -n '18,25p' nginx.conf.base_name >extra/bbs.conf # 放入指目錄 extra。

[root@lnmp02 conf]# sed -n '26,33p' nginx.conf.base_name #  取出第三個 server 標籤。

    server {

        listen       80;

        server_name  blog.etiantian.org;

        location / {

            root   html/blog;

            index  index.html index.htm;

        }

    }

[root@lnmp02 conf]# sed -n '26,33p' nginx.conf.base_name >extra/blog.conf  # 放入指定目錄 extra

[root@lnmp02 conf]# ls -l extra/    #  三個文件每一個文件包含本身的虛擬主機。

total 12

-rw-r--r-- 1 root root 185 Dec 20 23:17 bbs.conf

-rw-r--r-- 1 root root 187 Dec 20 23:17 blog.conf

-rw-r--r-- 1 root root 185 Dec 20 23:16 www.conf

[root@lnmp02 conf]# /application/nginx/sbin/nginx -t   # 檢查語法。

nginx: the configuration file /application/nginx-1.6.3/conf/nginx.conf syntax is ok

nginx: configuration file /application/nginx-1.6.3/conf/nginx.conf test is successful

[root@lnmp02 conf]# /application/nginx/sbin/nginx -s reload     #  平滑加載使配置生效。

[root@lnmp02 conf]# cat /etc/hosts    #  hosts 文件有域名對應 IP 的解析。

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4

::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

192.168.136.143 www.etiantian.org bbs.etiantian.org blog.etiantian.org

[root@lnmp02 conf]# curl www.etiantian.org  #  經過 curl 命令測試是否配置成功(成功)。   

www.etiantian.org

[root@lnmp02 conf]# curl bbs.etiantian.org  #  經過 curl 命令測試是否配置成功(成功)。   

bbs.etiantian.org

[root@lnmp02 conf]# curl blog.etiantian.org  #  經過 curl 命令測試是否配置成功(成功)。   

blog.etiantian.org

相關文章
相關標籤/搜索