日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

nginx介绍(三) - 虚拟主机

發布時間:2024/4/15 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 nginx介绍(三) - 虚拟主机 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

前言

  前面提到過, 由nginx來分發請求到tomcat中, 那么怎么來區分這些tomcat呢??

  我們一般訪問網站的時候, 是不是可以使用 ip : port (127.0.0.1:8080)的方式來訪問, 或者是 域名 : port (www.baidu.com:80), 只不過這里可以不寫端口, 這是由于使用了默認的端口.

  那么在nginx分發的時候, 是不是也可以通過 區分 域名 和 port 的方式來區分使用tomcat呢?

  注: 同一個ip下面, 可以綁定多個域名, 但是一個域名, 只能有一個ip. 如果一個ip上面綁定了多個域名, 假如 127.0.0.1 綁定了 www.hao123.com 和 www.google.com, 那么在訪問的時候, 給人的感覺, 是不是好像是我訪問了不同的服務器, 并且, 他們都是使用默認80端口訪問的.

?

一. 通過端口區分虛擬主機

1. 將nginx/html文件夾拷貝幾份

[root@localhost nginx]# cp -r html html-8081 [root@localhost nginx]# cp -r html html-8082

接下來, 修改 html-8081, html-8082 下面的index.html文件

在歡迎的地方, 加上了各自的端口顯示.

?

2. 修改配置文件

在server節點下面, 繼續添加兩個server節點, 主要修改其 listen , location.root 這兩個地方

server {listen 8081;server_name localhost;#charset koi8-r;#access_log logs/host.access.log main; location / {root html-8081;index index.html index.htm;}#error_page 404 /404.html;# redirect server error pages to the static page /50x.html# error_page 500 502 503 504 /50x.html;location = /50x.html {root html;} }server {listen 8082;server_name localhost;#charset koi8-r;#access_log logs/host.access.log main; location / {root html-8082;index index.html index.htm;}#error_page 404 /404.html;# redirect server error pages to the static page /50x.html# error_page 500 502 503 504 /50x.html;location = /50x.html {root html;} }

?

3. 刷新配置

[root@localhost sbin]# ./nginx -s reload

?

4. 查看結果

同一個ip下, 通過不同端口, 確實訪問到了不同的頁面.?

??

二. 通過域名來區分

?1. 將html再復制幾個

[root@localhost nginx]# cp -r html html-hao123 [root@localhost nginx]# cp -r html html-google

?

2. 為默認訪問的index.html加一個小尾巴

?

3. 修改nginx配置文件?

server { listen 80; server_name www.hao123.com;#charset koi8-r;#access_log logs/host.access.log main; location / { root html-hao123;index index.html index.htm;}#error_page 404 /404.html;# redirect server error pages to the static page /50x.html# error_page 500 502 503 504 /50x.html;location = /50x.html {root html;} }server { listen 80; server_name www.google.com;#charset koi8-r;#access_log logs/host.access.log main; location / { root html-google;index index.html index.htm;}#error_page 404 /404.html;# redirect server error pages to the static page /50x.html# error_page 500 502 503 504 /50x.html;location = /50x.html {root html;} }

?

4.? 刷新配置

[root@localhost sbin]# ./nginx -s reload

?

5. 修改客戶端的host文件, 將www.baidu.com , www.google.com 映射進去

?

?

?6. 驗證結果

乍一看, 我訪問的是 hao123 和 google 啊, 怎么跑到我部署的nginx里面去了呢. 罒ω罒

轉載于:https://www.cnblogs.com/elvinle/p/8268112.html

總結

以上是生活随笔為你收集整理的nginx介绍(三) - 虚拟主机的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。