<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                # nginx配置文件和虛擬主機 [TOC] ## 一、默認配置詳解[nginx.conf] nginx默認會生成一個主配置的備份,以便主配置文件誤修改后可以作為參考,將其過濾掉注釋文件和空格后,進行講解 ```sh egrep -v "#|^$" /app/nginx/nginx.conf.default ``` ![nginx配置](http://noah-pic.oss-cn-chengdu.aliyuncs.com/pic/20200305/215758937.png) ## 二、 虛擬主機詳解 ### 1.概念 所謂虛擬主機,在web服務里就是一個單獨的網站站點,這個站點有獨立的域名(或ip或端口),具有獨立的程序及資源目錄,可以獨立地對外提供服務供用戶訪問 在nginx中,每個server{ }標簽就對應一個虛擬主機,在apache中,每對<VirtualHost></VirtualHost>標簽對應一個虛擬主機 虛擬主機的三種類型: * 基于域名的虛擬主機[重點] * 基于端口的虛擬主機 * 基于IP的虛擬主機 重點掌握第一種基于域名的虛擬主機 ### 2.Nginx配置虛擬主機步驟 1. 增加一個完整的server標簽到結尾處,注意要在http標簽內 2. 更改server_name及對應網頁的root根目錄等參數 4. 創建server_name域名對應的網頁的根目錄,并建立測試的index.html首頁文件 4. 檢查Nginx配置文件語法(-t),平滑重啟(reload) 5. 在客戶端對server_name處配置的域名或host解析 6. 在windows瀏覽器中輸入地址訪問,或在linux中用curl訪問 說明:實際企業環境中,需要在nginx重啟后立即檢查結果,一般不采用敲命令檢查,而采用編寫檢查腳本手工執行或修改nginx啟動腳本自動執行的方式 ### 3.基于域名的虛擬主機實戰 1)修改nginx.conf文件為如下內容 ```sh 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.omg; location / { root html/www; index index.html index.htm; } } server { listen 80; server_name blog.etiantian.omg; location / { root html/blog; index index.html index.htm; } } } ``` 省略其他參數后配置了2個域名到server標簽模塊中 2)在nginx目錄下創建html/www和html/blog文件夾,并創建文件index.html,輸入任意內容 ```sh mkdir -p html/www echo "the pag is my www test" >html/www/index.html echo "the pag is my blog test" >html/www/index.html ./sbin/nginx -t ./sbin/nginx -s reload ``` 需要檢查語法并重啟nginx服務 3) 然后分別修改本機和windows客戶端的host文件后訪問本域名,查看結果 ```sh [root@xxx ~]# curl www.etiantian.omg the pag is my www test [root@xxx ~]# curl blog.etiantian.omg the pag is my blog test ``` 以上方法就創建了兩個域名虛擬主機,基于端口和基于ip的虛擬主機只需要更改server_name即可 ### 4.nginx虛擬主機的別名 虛擬主機別名,就是例如訪問www.baidu.com和訪問baidu.com這兩個域名,都能訪問到www.baidu.com這個域名,注意和301跳轉是不一樣的 設置方法很簡單,就是在server標簽中,第一個域名后面,接空格后再輸入第二個域名,如下: ```sh server { listen 80; server_name blog.etiantian.omg etiantian.omg; ``` 在生產場景中,一種應用就是上面寫的多個域名指向同一個頁面,另一種應用是再集群環境下,給每一臺服務器在主域名后配置不同
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看