Apache 配置虛擬機器主機之2--基於 IP

來源:互聯網
上載者:User

標籤:虛擬機器主機   ffffff   color   style   

  • 基於 name-based
  • 基於 IP
  • 基於 port
  • 結合

 

二、基於IP

配置hosts,httpd.conf,eno

1、假設伺服器已有IP為192.168.136.140,使用ifconfig在同一個網路介面eno16777736(或者eth0)綁定另外2個IP,或者同 nmtui 配置。可以進行ping探測。

[[email protected] ~]# ifconfig eno16777736:192.168.136.143
[[email protected] ~]# ifconfig eno16777736:192.168.136.144
2、修改/etc/hosts檔案,添加一一對應的網域名稱
# IP-Based
192.168.136.143    www3.example.com
1921.68.136.144    www4.example.com

3、建立虛擬機器主機存放網頁的根目錄

# /var/www 目錄結構[[email protected] www]# tree.├── cgi-bin├── html├── logs│   ├── www1│   │   ├── access_log│   │   └── error_log│   ├── www2│   │   ├── access_log│   │   └── error_log│   ├── www3│   │   ├── access_log│   │   └── error_log│   └── www4│   ├── access_log│   └── error_log└── vhosts    ├── www1    │   └── index.html    ├── www2    │   └── index.html    ├── www3    │   └── index.html    └── www4        └── index.html

index.html內容分別如下

[[email protected] www3]# cat index.html ../www4/index.html Holle world!Welcom to www3.example.com site with IP-Based.Holle world!Welcom to www4.example.com site with IP-Based.

4、在httpd.conf中將附加設定檔httpd-vhosts.conf包含進來,接著修改httpd-vhosts.conf配置

# IP-Based
<VirtualHost 192.168.136.143:80>    ServerAdmin [email protected]    ServerName www3.example.com    DocumentRoot "/var/www/vhosts/www3"    ErrorLog "/var/www/logs/www1/error_log"    CustomLog "/var/www/logs/www1/access_log" combined</VirtualHost><VirtualHost 192.168.136.144:80>    ServerAdmin [email protected]    ServerName www4.example.com    DocumentRoot "/var/www/vhosts/www4"    ErrorLog "/var/www/logs/www4/error_log"    CustomLog "/var/www/logs/www4/access_log" combined</VirtualHost>

5、配置語法檢查 httpd -S,可看到Name-Based和IP-Based共存。

[[email protected] www]# httpd -SVirtualHost configuration:192.168.136.143:80     www3.example.com (/etc/httpd/conf/httpd.conf:98)192.168.136.144:80     www4.example.com (/etc/httpd/conf/httpd.conf:106)*:80                   is a NameVirtualHost         default server www1.example.com (/etc/httpd/conf/httpd.conf:82)         port 80 namevhost www1.example.com (/etc/httpd/conf/httpd.conf:82)                 alias example1.com         port 80 namevhost www2.example.com (/etc/httpd/conf/httpd.conf:89)ServerRoot: "/etc/httpd"Main DocumentRoot: "/var/www/html"Main ErrorLog: "/etc/httpd/logs/error_log"Mutex authn-socache: using_defaultsMutex default: dir="/run/httpd/" mechanism=default Mutex mpm-accept: using_defaultsMutex authdigest-opaque: using_defaultsMutex proxy-balancer-shm: using_defaultsMutex rewrite-map: using_defaultsMutex authdigest-client: using_defaultsMutex proxy: using_defaultsPidFile: "/run/httpd/httpd.pid"Define: DUMP_VHOSTSDefine: DUMP_RUN_CFGUser: name="apache" id=48Group: name="apache" id=48

6、重啟服務 systemctl restart httpd.service,然後訪問4個網站。

[[email protected] www]# curl www1.example.com  www2.example.com www3.example.com www4.example.comHolle world!welcome to www1.example.com site with Name-Based.Holle world!welcome to www2.example.com site with Name-Based.Holle world!Welcom to www3.example.com site with IP-Based.Holle world!Welcom to www4.example.com site with IP-Based.
# 通過IP或者網域名稱訪問3,4[[email protected] www]# curl www3.example.com  192.168.136.143:80  www4.example.com 192.168.136.144:80Holle world!Welcom to www3.example.com site with IP-Based.Holle world!Welcom to www3.example.com site with IP-Based.Holle world!Welcom to www4.example.com site with IP-Based.Holle world!Welcom to www4.example.com site with IP-Based.

至此已完成了IP-Based的配置。

附:http://httpd.apache.org/docs/2.4/vhosts/ip-based.html

650) this.width=650;" title="image" style="border-left- 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-right: 0px; border-top-width: 0px" border="0" alt="image" src="http://s3.51cto.com/wyfs02/M00/8B/92/wKiom1hRFtjgaraUAAJZgR_1E9s225.png" width="1591" height="924" />

 

 

問題:使用者如何配置和管理。

Apache 配置虛擬機器主機之2--基於 IP

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.