時間:2023-07-17 13:27:01 | 來源:網(wǎng)站運營
時間:2023-07-17 13:27:01 來源:網(wǎng)站運營
nginx虛擬主機的配置:在真實的服務器環(huán)境,為了充分利用服務器資源,一臺nginx web服務器會同時配置N個虛擬主機,這樣可以充分利用服務器的資源,方便管理員的統(tǒng)一管理http{......省略其他代碼 #第一臺虛擬主機 server { listen 80; server_name a.jkyst.xyz; #這里域名一定不要重復 access_log logs/a.access.log; #日志需求可以根據(jù)自己的要求去做,如果覺得日志無所謂分不分開大可以放到一起 location{ root html/a; #這里是網(wǎng)站的根目錄,注意為了測試一定要分開,里面寫上不同的html index index.html index.htm; } ......這里省略其他代碼 } #第二臺虛擬主機 server{ listen 80; server_name b.jkyst.xyz; access_log logs/b.access.log; location{ root html/b; index index.html index.htm; } ......這里省略其他代碼 } #第三臺虛擬主機 server{ listen 80; server_name c.jkyst.xyz; access_log logs/c.access.log; location{ root html/c; index index.html index.htm; } }}
http{......省略其他代碼 #第一臺虛擬主機 server { listen 8000; server_name www.jkyst.xyz; access_log logs/a.access.log; location{ root html/a; index index.html index.htm; } ......省略其他代碼 } #第二臺虛擬主機 server{ listen 8001; server_name www.jkyst.xyz; access_log logs/b.access.log; location{ root html/b; index index.html index.htm; } ......省略其他代碼 } #第三臺虛擬主機 server{ listen 8002; server_name www.jkyst.xyz; access_log logs/c.access.log; location{ root html/c; index index.html index.htm; } ......省略其他代碼 }}
http{......省略其他代碼 #第一臺虛擬主機 server { listen IP地址:80; server_name a.jkyst.xy或者ip地址; access_log logs/a.access.log; location{ root html/a; index index.html index.htm; } ......省略其他代碼 } #第二臺虛擬主機 server{ listen IP地址:80; server_name b.jkyst.xyz或者IP地址; access_log logs/b.access.log; location{ root html/b; index index.html index.htm; } ......省略其他代碼 } #第三臺虛擬主機 server{ listen IP地址:80; server_name c.jkyst.xyz或者IP地址; access_log logs/c.access.log; location{ root html/c; index index.html index.htm; } ......省略其他代碼 }}
root@jia:~# lsb_release -aNo LSB modules are available.Distributor ID: UbuntuDescription: Ubuntu 19.10Release: 19.10Codename: eoanroot@jia:~# cat /proc/versionLinux version 5.3.0-18-generic (buildd@lcy01-amd64-027) (gcc version 9.2.1 20190909 (Ubuntu 9.2.1-8ubuntu1)) #19-Ubuntu SMP Tue Oct 8 20:14:06 UTC 2019
nginx版本:root@jia:~# nginx -vnginx version: nginx/1.16.1 (Ubuntu)
root@jia:/var/www/html# cat /etc/nginx/conf.d/default.conf server { listen 80; server_name a.jkyst.xyz; location / { root /var/www/html/a; index index.html index.htm; }}server { listen 80; server_name b.jkyst.xyz; location / { root /var/www/html/b; index index.html index.htm; }}server { listen 80; server_name c.jkyst.xyz; location / { root /var/www/html/c; index index.html index.htm; }
記住修改配置文件后一定要重新啟動nginxroot@jia:~# systemctl restart nginx
root@jia:~# cd /var/www/html/root@jia:/var/www/html# mkdir a b c#生成主頁文件root@jia:/var/www/html# echo a.jkyst.xyz > a/index.htmlroot@jia:/var/www/html# echo b.jkyst.xyz > b/index.htmlroot@jia:/var/www/html# echo c.jkyst.xyz > c/index.html
127.0.0.1 a.jkyst.xyz //127.0.0.1是nginx服務器的IP地址,我這里使用的是同一臺PC127.0.0.1 b.jkyst.xyz 127.0.0.1 c.jkyst.xyz
root@jia:~# curl a.jkyst.xyz a.jkyst.xyzroot@jia:~# curl b.jkyst.xyz b.jkyst.xyzroot@jia:~# curl c.jkyst.xyz c.jkyst.xyz
OK發(fā)現(xiàn)訪問的都是我想要得到的域名,證明基于域名的虛擬主機配置成功關(guān)鍵詞:配置,主機,虛擬
微信公眾號
版權(quán)所有? 億企邦 1997-2025 保留一切法律許可權(quán)利。