Apache 配置虛擬機器主機之1--基於名稱(name-based)

來源:互聯網
上載者:User

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

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

 

一、基於名稱(name-based)

需要配置 hosts,httpd.conf

 

實驗環境需求:

2個網域名稱:www1.example.com www2.example.com

IP:192.168.136.140

連接埠:80

 

檔案目錄。/var/www目錄下的結構如下。

[[email protected] www]# tree.├── cgi-bin├── html├── logs│   ├── www1│   │   ├── access_log│   │   └── error_log│   └── www2│   └── error_log└── vhosts    ├── www1    │   └── index.html    └── www2        └── index.html10 directories, 3 files

index.html的內容如下

[[email protected] www]# cat /var/www/vhosts/www[12]/*

Holle world!
welcome to www1.example.com site.
Holle world!
welcome to www2.example.com site.

 

# 編輯本地DNSvim /etc/hosts# 添加多網域名稱的記錄192.168.136.140 www1.example.com www2.example.com# 添加 Name-Based 虛擬機器主機塊配置vim /etc/httpd/conf/httpd.conf
## Name-Based ####################################################<VirtualHost *:80>    # This first-listed virtual host is also the default for *:80 第一個虛擬機器主機為預設主控件    ServerName www1.example.com    ServerAlias example1.com    DocumentRoot "/var/www/vhosts/www1"</VirtualHost><VirtualHost *:80>    ServerName www2.example.com    #ServerAlias example2.com    DocumentRoot "/var/www/vhosts/www2"</VirtualHost>#################################################################### 檢查配置文法 *:80    is a NameVirtualHost 這裡能正常解析,文法OK[[email protected] vhosts]# httpd -SVirtualHost configuration:*: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 proxy: using_defaultsMutex 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_defaultsPidFile: "/run/httpd/httpd.pid"Define: DUMP_VHOSTSDefine: DUMP_RUN_CFGUser: name="apache" id=48Group: name="apache" id=48[[email protected] vhosts]# # 重啟 httpdsystemctl restart httpd.servicesystemctl status httpd.service[[email protected] vhosts]# systemctl status httpd.service -l● httpd.service - The Apache HTTP Server   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)   Active: active (running) since Wed 2016-12-14 15:56:58 CST; 26min ago     Docs: man:httpd(8)           man:apachectl(8)  Process: 5951 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=0/SUCCESS) Main PID: 5957 (httpd)   Status: "Total requests: 9; Current requests/sec: 0; Current traffic:   0 B/sec"   Memory: 4.1M   CGroup: /system.slice/httpd.service           ├─5957 /usr/sbin/httpd -DFOREGROUND           ├─5958 /usr/sbin/httpd -DFOREGROUND           ├─5959 /usr/sbin/httpd -DFOREGROUND           ├─5960 /usr/sbin/httpd -DFOREGROUND           ├─5962 /usr/sbin/httpd -DFOREGROUND           ├─5975 /usr/sbin/httpd -DFOREGROUND           ├─5978 /usr/sbin/httpd -DFOREGROUND           ├─5979 /usr/sbin/httpd -DFOREGROUND           ├─5980 /usr/sbin/httpd -DFOREGROUND           ├─5981 /usr/sbin/httpd -DFOREGROUND           └─6233 /usr/sbin/httpd -DFOREGROUNDDec 14 15:56:58 docker1 systemd[1]: Starting The Apache HTTP Server...Dec 14 15:56:58 docker1 httpd[5957]: AH00558: httpd: Could not reliably determine the server‘s fully qualified domain name, using 192.168.136.140. Set the ‘ServerName‘ directive globally to suppress this messageDec 14 15:56:58 docker1 systemd[1]: Started The Apache HTTP Server.[[email protected] vhosts]# # 驗證通過網域名稱訪問[[email protected] vhosts]# curl 127.0.0.1

Holle world!
welcome to www1.example.com site.

[[email protected] vhosts]# curl www1.example.com

Holle world!
welcome to www1.example.com site.

[[email protected] vhosts]# curl www2.example.com

Holle world!
welcome to www2.example.com site.

現在基於主機名稱的配置已完成。

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

650) this.width=650;" title="image_thumb[2]" 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_thumb[2]" src="http://s3.51cto.com/wyfs02/M01/8B/92/wKiom1hRFwvxJJjfAAVqdMuDxao854.png" width="1122" height="663" />

Apache 配置虛擬機器主機之1--基於名稱(name-based)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.