nginx 請求多個域名指定對應的根目錄


同一個nginx配置文件,請求不同的域名可以指定對應的目錄

  • nginx配置
cat long.conf

server {
        listen       80;

        server_name  a.com b.com c.com;


	location / {
		root /home/long/$host/;
		index index.html;
	}


        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

   }
  • 創建對應的目錄
cd /home/long
mkdir a.com b.com c.com
#對應目錄下創建index.html文件
echo 'test a.com' a.com/index.html
...
  • 訪問測試
    本地測試,需將nginx所在的ip和域名加入到hosts里



免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM