Nginx怎么實(shí)現(xiàn)一個(gè)服務(wù)配置多個(gè)站點(diǎn)

一個(gè)服務(wù)配置多個(gè)站點(diǎn)

server?{ ?listen?80; ?server_name?a.ops-coffee.cn;  ?location?/?{ ?root?/home/project/pa; ?index?index.html; ?} }  server?{ ?listen?80; ?server_name?ops-coffee.cn?b.ops-coffee.cn;  ?location?/?{ ?root?/home/project/pb; ?index?index.html; ?} }  server?{ ?listen?80; ?server_name?c.ops-coffee.cn;  ?location?/?{ ?root?/home/project/pc; ?index?index.html; ?} }

基于nginx虛擬主機(jī)配置實(shí)現(xiàn),Nginx有三種類型的虛擬主機(jī)

基于IP的虛擬主機(jī): 需要你的服務(wù)器上有多個(gè)地址,每個(gè)站點(diǎn)對(duì)應(yīng)不同的地址,這種方式使用的比較少

基于端口的虛擬主機(jī): 每個(gè)站點(diǎn)對(duì)應(yīng)不同的端口,訪問的時(shí)候使用ip:port的方式訪問,可以修改listen的端口來(lái)使用

基于域名的虛擬主機(jī): 使用最廣的方式,上邊例子中就是用了基于域名的虛擬主機(jī),前提條件是你有多個(gè)域名分別對(duì)應(yīng)每個(gè)站點(diǎn),server_name填寫不同的域名即可

? 版權(quán)聲明
THE END
喜歡就支持一下吧
點(diǎn)贊12 分享