nginx通過域名區(qū)分不同虛擬機<3>

什么是域名
域名就是網站。

www.baidu.com
www.taobao.com
www.jd.com

Tcp/ip

Dns服務器:把域名解析為ip地址。保存的就是域名和ip的映射關系。

一級域名:
Baidu.com
Taobao.com
Jd.com

二級域名:
www.baidu.com
Image.baidu.com
Item.baidu.com

三級域名:

Image.baidu.com
Aaa.image.baidu.com

一個域名對應一個地址,一個ip地址可以被多個域名綁定。本地測試可以修改文件。

修改window的hosts文件:C:\Windows\System32\drivers\etc\host
打開后直接在后面加ip:域名鍵值對即可。

可以配置域名和ip的映射關系,如果hosts文件中配置了域名和ip的對應關系,不需要走dns服務器。


image.png
  1. 在C:\Windows\System32\drivers\etc\hosts中添加

192.168.231.129 www.test1.com
192.168.231.129 www.test2.com

  1. 在nginx.conf中配置:

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }
    }
    server {
        listen       81;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html-81;
            index  index.html index.htm;
        }
    }
    server {
        listen       80;
        server_name  www.test1.com;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html-test1;
            index  index.html index.htm;
        }
    }
      server {
        listen       80;
        server_name  www.test2.com;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html-test2;
            index  index.html index.htm;
        }
    }
}

3.分別復制一份html文件,命名為html-test1,html-test2。修改html/index.html中的標題,用來區(qū)別不同的網站

  1. nginx重新加載配置文件

sbin/nginx -s reload

5.在瀏覽器中分別輸入
www.test1.com
www.test2.com

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

  • Nginx簡介 解決基于進程模型產生的C10K問題,請求時即使無狀態(tài)連接如web服務都無法達到并發(fā)響應量級一萬的現...
    魏鎮(zhèn)坪閱讀 2,230評論 0 9
  • 閱讀之前,建議先閱讀初識 Nginx。 之后,我們來了解一下 Nginx 配置。 抽象來說,將 Nginx 配置為...
    思夢PHP閱讀 1,397評論 2 10
  • 第一章 Nginx簡介 Nginx是什么 沒有聽過Nginx?那么一定聽過它的“同行”Apache吧!Ngi...
    JokerW閱讀 33,038評論 24 1,002
  • 在React中,常用Redux來做一些業(yè)務邏輯處理。Redux提供了中間件的寫法,可以對Redux中的數據流做一些...
    VictorLiang閱讀 737評論 0 1
  • 年輕人最迷茫的就是不知道自己這一生應該做些什么。是的,我就是這些年輕人其中的一個,我很迷茫,非常迷茫。 有些人很幸...
    深水里的星星閱讀 326評論 1 1

友情鏈接更多精彩內容