多站點使用入口檔案的方式控制,要新增乙個站點,直接在public目錄裡面新增乙個入口檔案即可。
## 新增多站點(以index+admin站點為例)
### 1. 子網域名稱方式
- apache伺服器
1. 站點配置。在apache的httpd-vhost中加入兩個站點的配置:
# 預設站點配置
directoryindex index.php
documentroot "/directory/to/your-project/public"
servername 您的網域名稱
# admin子站點配置
directoryindex admin.php
documentroot "/directory/to/your-project/public"
servername 您的admin子網域名稱
2. 重寫規則配置(站點public目錄下的.htaccess檔案)
1. 修改預設重寫規則,新增網域名稱限制。
# 在上面新增一行網域名稱限制
rewritecond % ^您的網域名稱$ [nc]
# 一下為原本的配置資訊
rewritecond % !-d
rewritecond % !-f
rewriterule ^(.*)$ index.php/$1 [qsa,pt,l]
2. 目錄中加入重寫規則:
rewritecond % ^您的admin子網域名稱$ [nc]
rewritecond % !-d
rewritecond % !-f
rewriterule ^(.*)$ admin.php/$1 [qsa,pt,l]
完整的.htaccess檔案內容:
options +followsymlinks -multiviews
rewriteengine on
# 預設站點重寫規則
rewritecond % ^您的網域名稱$ [nc]
rewritecond % !-d
rewritecond % !-f
rewriterule ^(.*)$ index.php/$1 [qsa,pt,l]
# admin子站點重寫規則
rewritecond % ^您的admin子網域名稱$ [nc]
rewritecond % !-d
rewritecond % !-f
rewriterule ^(.*)$ admin.php/$1 [qsa,pt,l]
- nginx伺服器
在nginx伺服器中,同樣新增乙個admin子網域名稱的站點,預設訪問檔案改為admin.php即可,完整的nginx配置檔案如下:
# 預設站點配置
server {
listen 80;
server_name 您的網域名稱;
root /directory/to/your-project/public;
location / {
index index.html index.htm index.php;
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=/$1 last;
break;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param script_filename $document_root$fastcgi_script_name;
include fastcgi_params;
# admin子站點配置
server {
listen 80;
server_name 您的admin子網域名稱;
root /directory/to/your-project/public;
location / {
index admin.php;
if (!-e $request_filename) {
rewrite ^(.*)$ /admin.php?s=/$1 last;
break;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param script_filename $document_root$fastcgi_script_name;
include fastcgi_params;
> 以上配置資訊中,您需要將目錄名及網域名稱改為您的目錄及網域名稱。
> 如果需要配置https等資訊,請自行新增https證書配置即可。
## 2.
多站點實現的兩種方式:
1. 使用子網域名稱。
優點:1. 不會汙染url,不需要再url中加入入口檔名。
3. apache必須開啟rewrite模組。一般在使用thinkphp框架時,已經開啟了重寫模組,所以這個限制問題不大。
3. 考慮apache中是否可以通過htaccess檔案配置,解決伺服器自動配置的問題。
2. url中加入對應入口檔案路徑。
1. 優點:可以做到開箱即用。不需要修改伺服器配置。
2. 缺點:會汙染url。前端處理麻煩,需要統一配置url字首,並在前端ajax請求及對應url跳轉時加入字首。需要修改的地方太多。
3. 前端需要解決預設站點不帶字首與其他站點帶字首的問題。(根據訪問url與pathinfo,自動處理字首,並將字首傳送到前端)
考慮怎麼將兩種用法綜合,使用者可以開箱即用,及在url中加入對應入口檔案,並可通過預設入口檔案放人預設站點。也可通過配置子網域名稱,去除url汙染。
> 首選實現1,然後再1的基礎上實現2。
阿里雲nginx建立多站點
最近開始用阿里雲的vps,用了它的一鍵安裝包安裝了php環境,nginx的。下面記錄建立多站點的心得。首先php安裝好後會自帶安裝乙個phpwind的站點。檔案目錄存放在 alidata www 下 配置檔案是分開單獨存放的,注意網上的很多都不准 phpwind的配置檔案 alidata serve...
php多域名單站點路由
能夠使多網域名稱但是只有乙個站點的小站,通過路由訪問到各個指定目錄 網域名稱跳轉路由 預設跳轉 default 自定義網域名稱路由 echo server http host 獲取當前網域名稱 gopage default if array key exists currenthost,router...
Apache 多網域名稱多站點設定
httpd.conf 檔案 找到serveradmin 前面打上 不含雙引號 也就是把這段注釋掉.找到documentroot d program files apache2.2 htdocs 這個是你安裝apache的位置,自己應該曉得 把這段也打上 注釋掉.假如,虛擬空間的各個站點都在d盤的ww...