<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>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                ### 創建 Apache 虛擬主機 使用 ERB 模板配置虛擬主機是一種常見的應用, 因為每個虛擬主機配置的實例通常都使用類似的樣板代碼,只有一兩個變量的值不同而已。 顯然,對于某些網站或應用程序來說,你需要在虛擬主機的定義中指定特殊的配置選項, 然而這些特殊選項又不能通過一個簡單的模板來配置?—?但是,不管怎樣, 使用一個模板配置一些簡單的站點將會節省時間、避免重復勞動。 #### 操作步驟 1. 添加如下代碼到 /etc/puppet/modules/apache/manifests/init.pp: ``` define site( $sitedomain = "", $documentroot = "" ) { include apache if $sitedomain == "" { $vhost_domain = $name } else { $vhost_domain = $sitedomain } if $documentroot == "" { $vhost_root = "/var/www/${name}" } else { $vhost_root = $documentroot } file { "/etc/apache2/sites-available/${vhost_domain}.conf": content =&gt; template("apache/vhost.erb"), require =&gt; File["/etc/apache2/conf.d/name-basedvhosts.conf"], notify =&gt; Exec["enable-${vhost_domain}-vhost"], } exec { "enable-${vhost_domain}-vhost": command =&gt; "/usr/sbin/a2ensite ${vhost_domain}.conf", require =&gt; [ File["/etc/apache2/sites-available/${ vhost_domain}.conf"], Package["apache2-mpm-prefork"] ], refreshonly =&gt; true, notify =&gt; Service["apache2"], } } ``` 2. 使用如下內容創建 /etc/puppet/modules/apache/templates/vhost.erb 文件: ``` &lt;VirtualHost *:80&gt; ServerName &lt;%= vhost_domain %&gt; ServerAdmin admin@&lt;%= vhost_domain %&gt; DocumentRoot &lt;%= vhost_root %&gt; ErrorLog logs/&lt;%= vhost_domain %&gt;-error_log CustomLog logs/&lt;%= vhost_domain %&gt;-access_log common &lt;Directory /var/www/&lt;%= vhost_domain %&gt;&gt; Allow from all Options +Includes +Indexes +FollowSymLinks AllowOverride all &lt;/Directory&gt; &lt;/VirtualHost&gt; &lt;VirtualHost *:80&gt; ServerName www.&lt;%= vhost_domain %&gt; Redirect 301 / http://&lt;%= vhost_domain %&gt;/ &lt;/VirtualHost&gt; ``` 3. 添加如下代碼到一個節點: ``` apache::site { "keithlard.com": } ``` 4. 運行 Puppet: ``` # puppet agent --test info: Retrieving plugin info: Caching catalog for cookbook.bitfieldconsulting.com info: Applying configuration version '1309190720' notice: /Stage[main]//Node[cookbook]/Apache::Site[keithlard.com]/ File[/etc/apache2/sites-available/keithlard.com.conf]/ensure: defined content as '{md5}f2a558c02beeaed4beb7da250821b663' info: /Stage[main]//Node[cookbook]/Apache::Site[keithlard.com]/ File[/etc/apache2/sites-available/keithlard.com.conf]: Scheduling refresh of Exec[enable-keithlard.com-vhost] notice: /Stage[main]//Node[cookbook]/Apache::Site[keithlard.com]/ Exec[enable-keithlard.com-vhost]: Triggered 'refresh' from 1 events info: /Stage[main]//Node[cookbook]/Apache::Site[keithlard. com]/Exec[enable-keithlard.com-vhost]: Scheduling refresh of Service[apache2] notice: /Stage[main]/Apache/Service[apache2]: Triggered 'refresh' from 2 events notice: Finished catalog run in 3.79 seconds ``` #### 工作原理 名為 apache::site 的 define 使用 vhost.erb 模板生成 Apache 虛擬主機的定義。 默認情況下,假設站點的域名與站點實例的名字相同,本例中是 keithlard.com。 所以當 Puppet 看到如下代碼時: ``` apache::site { "keithlard.com": } ``` 它就使用 keithlard.com 作為站點域名。如果你要指定不同的域名,請添加 sitedomain 參數: ``` apache::site { "networkr_production": sitedomain => "networkr.com", } apache::site { "networkr_staging": sitedomain => "staging.networkr.com", } ``` 模板系統的優秀之處在于:如果你想為所有站點重新配置一個值(例如,更改管理員的 e-mail 地址), 你只需要修改一次模板,Puppet 就會根據模板相應地更新所有的虛擬主機。 同樣地,如果你需要為虛擬主機指定與默認值(/var/www/${name})不同的 DocumentRoot, 請添加如下的 documentroot 參數: ``` apache::site { "communitysafety.org": documentroot => "/var/apps/commsafe", } ``` #### 更多用法 在前面的例子中,我們只在模板中定義了一個變量,但只要你愿意,你可以使用更多的變量。 它們也可以是 **facts**,例如: ``` ServerName <%= fqdn %> ``` 或者 Ruby 表達式: ``` ServerAdmin<%= emails["admin"] %> ``` 或者任何你要執行的 Ruby 代碼: ``` ServerAdmin <%= vhost_domain == 'coldcomfort.com' ? 'seth@coldcomfort. com' : 'flora@poste.com' %> ``` #### 參見本書 * 第 5 章的 [在模板中遍歷數組](#ch05sec05) 一節
                  <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>

                              哎呀哎呀视频在线观看