天天看點

使用Nginx容器

   第一步配置nginx.conf

<code>server {</code>

<code>        </code><code>listen       80;</code>

<code>        </code><code>server_name  localhosttest.com;</code>

<code>        </code><code>#新配置的root路徑</code>

<code>        </code><code>root         </code><code>/usr/html/wwww</code><code>;</code>

<code>        </code><code>#charset koi8-r;</code>

<code>        </code><code>#access_log  logs/host.access.log  main;</code>

<code>        </code><code>location / {</code>

<code>           </code><code>#注釋掉原root路徑,使用上面配置的root路徑</code>

<code>           </code><code># root   html;</code>

<code>            </code><code>index  index.html index.htm;</code>

<code>        </code><code>}</code>

<code>        </code><code>#比對錯誤頁面</code>

<code>        </code><code>error_page  404              </code><code>/404</code><code>.html;</code>

<code>        </code><code># redirect server error pages to the static page /50x.html</code>

<code>        </code><code>#</code>

<code>        </code><code>error_page   500 502 503 504  </code><code>/50x</code><code>.html;</code>

<code>        </code><code>location = </code><code>/50x</code><code>.html {</code>

<code>            </code><code>#root   html;</code>

   第二步配置新的root

<code>[root@localhost wwww]</code><code># mkdir /usr/html/wwww -pv</code>

<code>[root@localhost wwww]</code><code># vim index.html</code>

<code>&lt;!DOCTYPE html&gt;</code>

<code>&lt;html lang=</code><code>"en"</code> <code>xmlns=</code><code>"http://www.w3.org/1999/xhtml"</code><code>&gt;</code>

<code>&lt;</code><code>head</code><code>&gt;</code>

<code>    </code><code>&lt;meta charset=</code><code>"utf-8"</code> <code>/&gt;</code>

<code>    </code><code>&lt;title&gt;New Document&lt;</code><code>/title</code><code>&gt;</code>

<code>    </code><code>&lt;meta name=</code><code>"generator"</code> <code>content=</code><code>"EverEdit"</code> <code>/&gt;</code>

<code>    </code><code>&lt;meta name=</code><code>"author"</code>  <code>content=</code><code>""</code> <code>/&gt;</code>

<code>    </code><code>&lt;meta name=</code><code>"keywords"</code> <code>content=</code><code>""</code> <code>/&gt;</code>

<code>    </code><code>&lt;meta name=</code><code>"description"</code> <code>content=</code><code>""</code>  <code>/&gt;</code>

<code>&lt;</code><code>/head</code><code>&gt;</code>

<code>&lt;body&gt;</code>

<code>&lt;h&gt;這是第一個HTML&lt;</code><code>/h</code><code>&gt;</code>

<code>                   </code> 

<code>&lt;</code><code>/body</code><code>&gt;</code>

<code>&lt;</code><code>/html</code><code>&gt;</code>

   第三步配置hosts

<code>[root@localhost wwww]</code><code># vim /etc/hosts</code>

<code>127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4 localhosttest.com</code>

<code>::1         localhost localhost.localdomain localhost6 localhost6.localdomain6</code>

   第四步重新開機Nginx:

<code>[root@localhost nginx]</code><code># kill -HUP $(cat /var/run/nginx/nginx.pid)</code>

<code>通路:http:</code><code>//localhosttest</code><code>.com</code>

本文轉自 夢朝思夕 51CTO部落格,原文連結:http://blog.51cto.com/qiangmzsx/1381582

繼續閱讀