首頁  >  文章  >  後端開發  >  註冊了網域之後,多個php項目可以用多個網域分別綁定嗎

註冊了網域之後,多個php項目可以用多個網域分別綁定嗎

WBOY
WBOY原創
2016-10-22 00:14:241027瀏覽

我註冊了好幾個域名,伺服器中部署的apache上運行的多個php項目,可以用多個域名分別綁定嗎?怎麼綁定啊

回覆內容:

我註冊了好幾個域名,伺服器中部署的apache上運行的多個php項目,可以用多個域名分別綁定嗎?怎麼綁定啊

可以的。使用virtualhost即可。
你的網域先使用A記錄全部解析到伺服器的IP
編輯http-vhost.conf設定

<code><VirtualHost *:80>
    DocumentRoot "D:/UPUPW_AP5.5/vhosts/hospital.com/web"
    ServerName hospital.com:80
    ServerAlias
    ServerAdmin webmaster@hospital.com
    DirectoryIndex index.html index.htm index.php default.php app.php u.php
    ErrorLog logs/hospital.com-error.log
    CustomLog logs/hospital.com-access_%Y%m%d.log comonvhost
<Directory "D:/UPUPW_AP5.5/vhosts/hospital.com/web">
    Options FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>
<LocationMatch "/(inc)/(.*)$">
    Require all denied
</LocationMatch>
<LocationMatch "/(attachment|attachments|uploadfiles|avatar)/(.*).(php|php5|phps|asp|asp.net|jsp)$">
    Require all denied
</LocationMatch>
</VirtualHost>
//D:/UPUPW_AP5.5/vhosts/hospital.com/web    WEB目录
//ServerName hospital.com:80 绑定的域名</code>

設定apacheVirtualHost,以我的專案為例:
找到伺服器的httpd.conf,然後設定下面內容:

<code class="html"><VirtualHost *:80>
     ServerName admin.example.com
     ProxyPass / http://localhost:8080/
     ProxyPassReverse / http://localhost:8080/
     ErrorLog logs/admin.example.com-error_log
     CustomLog logs/admin.example.com-access_log common
 </VirtualHost>

<VirtualHost *:80>
     ServerName www.demo.com
     ProxyPass / http://localhost:8081/
     ProxyPassReverse / http://localhost:8081/
     ErrorLog logs/demo.com-error_log
     CustomLog logs/demo.com-access_log common
 </VirtualHost></code>

上面的配置,是讓apache監聽80端口,也就是預設的端口,然後當用戶訪問admin.example.com的時候,就把請求分發到8080端口的應用。當使用者造訪www.demo.com的時候,就把請求分送到8081埠。當然,你有多少程序,就要配置多少個VirtualHost。如果還不明白,可以搜尋apache埠轉送,很多教學喔。

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn