Nginx基於域名的虛擬主機
阿新 • • 發佈:2020-08-19
1.在實驗中利用修改hosts檔案來實現兩個域名,並且建立好兩個網址網頁存放目錄
10.0.0.102 blog.ccku.cn
10.0.0.102 bbs.ccku.cn
#vim /usr/local/nginx/html/bbs/index.php
<?php
echo "welcome to php."
?>
#vim /usr/local/nginx/html/blog/index.html
welcome to my blog.
(2)在nginx主配置檔案中並列編寫兩個server標籤(注意:各個server塊是並列關係,不是包含關係)
server { #監聽的埠 listen 80; #伺服器域名 server_name blog.ccku.cn; #預設訪問的檔名稱,優先順序順序 index index.html index.htm index.php; #檔案相對路徑 root html/blog; #虛擬主機的訪問日誌,日誌檔案格式標籤為main(http塊中定義的log_format指令) access_log logs/blog-access.log main; } server { listen 80; server_name bbs.ccku.cn; index index.php index.html index.htm; root html/bbs; access_log logs/bbs-access.log main; }
#如果要支援解析php,在各自的server標籤中新增
location ~ \.php$ { #設定工作(檔案)路徑 root html/blog; #設定fastcgi伺服器的地址,可以是域名/IP地址/埠 fastcgi_pass 127.0.0.1:9000; #設定預設主頁,實際不起作用 fastcgi_index index.php; #指定匹配指令碼的檔案 fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; #呼叫fastcgi.conf檔案 include fastcgi.conf; }
#驗證: