2、基于IP的虛擬主機(jī)
3、基于端口的虛擬主機(jī)
且每一種虛擬主機(jī)均可通過(guò)“server{}" 配置段實(shí)現(xiàn)各自的" />

国产成人精品无码青草_亚洲国产美女精品久久久久∴_欧美人与鲁交大毛片免费_国产果冻豆传媒麻婆精东

15158846557 在線咨詢(xún) 在線咨詢(xún)
15158846557 在線咨詢(xún)
所在位置: 首頁(yè) > 營(yíng)銷(xiāo)資訊 > 網(wǎng)站運(yùn)營(yíng) > 杭州課工場(chǎng)IT培訓(xùn):搭建nginx虛擬主機(jī)——基于域名、端口和IP

杭州課工場(chǎng)IT培訓(xùn):搭建nginx虛擬主機(jī)——基于域名、端口和IP

時(shí)間:2023-07-15 07:51:01 | 來(lái)源:網(wǎng)站運(yùn)營(yíng)

時(shí)間:2023-07-15 07:51:01 來(lái)源:網(wǎng)站運(yùn)營(yíng)

杭州課工場(chǎng)IT培訓(xùn):搭建nginx虛擬主機(jī)——基于域名、端口和IP:

Nginx支持的虛擬主機(jī)有三種

1、基于域名的虛擬主機(jī)
2、基于IP的虛擬主機(jī)
3、基于端口的虛擬主機(jī)
且每一種虛擬主機(jī)均可通過(guò)“server{}" 配置段實(shí)現(xiàn)各自的功能

一、基于域名搭建

1、編譯安裝Nginx服務(wù)
2、遠(yuǎn)程獲取Windows上的源碼包,并掛載到Linux上

[root@localhost ~]# smbclient -L //192.168.235.1Enter SAMBA/root's password: Sharename Type Comment--------- ---- -------LNMP Disk [root@localhost ~]# mkdir /abc[root@localhost ~]# mount.cifs //192.168.235.1/LNMP /abcPassword for root@//192.168.235.1/LNMP: [root@localhost ~]# ls /abcDiscuz_X3.4_SC_UTF8.zip nginx-1.12.0.tar.gz php-7.1.10.tar.bz2mysql-boost-5.7.20.tar.gz nginx-1.12.2.tar.gz php-7.1.20.tar.gz3、解壓源碼包、下載安裝編譯組件包

[root@localhost ~]# cd /abc[root@localhost abc]# tar zxvf nginx-1.12.0.tar.gz -C /opt[root@localhost abc]# ls /optnginx-1.12.0 rh[root@localhost abc]# cd /opt[root@localhost opt]# yum install -y /> gcc / //C語(yǔ)言> gcc-c++ / //c++語(yǔ)言> pcre-devel / //pcre語(yǔ)言工具> zlib-devel //壓縮函數(shù)庫(kù)4、創(chuàng)建程序用戶并配置Nginx服務(wù)相關(guān)組件

[root@localhost opt]# useradd -M -s /sbin/nologin nginx//創(chuàng)建程序用戶nginx,并限定其不可登錄終端[root@localhost opt]# cd nginx-1.12.0/[root@localhost nginx-1.12.0]# ./configure / //配置nginx> --prefix=//usr/local/nginx / //指定安裝路徑 > --user=nginx ///指定用戶名> --group=nginx ///指定用戶所屬組> --with-http_stub_status_module//安裝狀態(tài)統(tǒng)計(jì)模塊5、編譯及安裝

[root@localhost nginx-1.12.0]# make && make install6、優(yōu)化Nginx服務(wù)啟動(dòng)腳本,并建立命令軟連接

[root@localhost nginx-1.12.0]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/ //創(chuàng)建nginx服務(wù)命令軟鏈接到系統(tǒng)命令[root@localhost nginx-1.12.0]# systemctl stop firewalld.service //關(guān)閉防火墻[root@localhost nginx-1.12.0]# setenforce 0//關(guān)閉增強(qiáng)型安全功能[root@localhost nginx-1.12.0]# nginx //輸入nginx 開(kāi)啟服務(wù)[root@localhost nginx-1.12.0]# netstat -ntap | grep 80 //查看服務(wù)的80 端口,顯示已開(kāi)啟tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 7520/nginx: master1、配置DNS域名解析服務(wù)

[root@localhost ~]# yum -y install bind//安裝DNS服務(wù)的bind包[root@localhost ~]# vim /etc/named.conf //編輯主配置文件options { listen-on port 53 { any; }; ##將監(jiān)聽(tīng)地址127.0.0.1替換為any, listen-on-v6 port 53 { ::1; }; directory "/var/named"; dump-file "/var/named/data/cache_dump.db"; statistics-file "/var/named/data/named_stats.txt"; memstatistics-file "/var/named/data/named_mem_stats.txt"; recursing-file "/var/named/data/named.recursing"; secroots-file "/var/named/data/named.secroots"; allow-query { any; }; ##將授權(quán)l(xiāng)ocalhost替換為any[root@localhost ~]# vim /etc/named.rfc1912.zones //編輯兩個(gè)域名的區(qū)域配置文件zone "kgc.com" IN { type master; file "kgc.com.zone"; allow-update { none; };}; zone "accp.com" IN { type master; file "accp.com.zone"; allow-update { none; };}; [root@localhost ~]# cd /var/named[root@localhost named]# cp -p named.localhost kgc.com.zone [root@localhost named]# cp -p named.localhost accp.com.zone [root@localhost named]# vim kgc.com.zone //編輯kgc域名區(qū)域數(shù)據(jù)配置文件$TTL 1D@ IN SOA @ rname.invalid. ( 0 ; serial 1D ; refresh 1H ; retry 1W ; expire 3H ) ; minimum NS @ A 127.0.0.1www IN A 192.168.235.158##刪除原來(lái)末行的內(nèi)容,添加域名解析地址為本機(jī)地址[root@localhost named]# vim accp.com.zone //編輯accp域名區(qū)域數(shù)據(jù)配置文件$TTL 1D@ IN SOA @ rname.invalid. ( 0 ; serial 1D ; refresh 1H ; retry 1W ; expire 3H ) ; minimum NS @ A 127.0.0.1www IN A 192.168.235.158##刪除原來(lái)末行的內(nèi)容,添加域名解析地址為本機(jī)地址[root@localhost named]# systemctl start named //開(kāi)啟dns服務(wù)[root@localhost named]# systemctl stop firewalld.service //關(guān)閉防火墻[root@localhost named]# setenforce 0 //關(guān)閉增強(qiáng)型安全功能1、配置虛擬主機(jī)
2、創(chuàng)建自測(cè)網(wǎng)頁(yè)

[root@localhost named]# cd [root@localhost ~]# mkdir -p /var/www/html/kgc[root@localhost ~]# mkdir -p /var/www/html/accp[root@localhost ~]# ls /var/www/html/accp kgc[root@localhost ~]# cd /var/www/html/[root@localhost html]# echo "this kgc web" > kgc/index.html[root@localhost html]# echo "this accp web" > accp/index.html3、編輯nginx.conf配置文件

[root@localhost html]# vim /usr/local/nginx/conf/nginx.confserver { listen 80; server_name www.kgc.com; charset utf-8; ##支持中文字符 access_log logs/www.kgc.com.access.log; ##kgc站點(diǎn)訪問(wèn)日志 location / { } error_page 500 502 503 504 /50x.html; ##服務(wù)端報(bào)錯(cuò)相關(guān)網(wǎng)頁(yè) location = /50x.html { root html; } }server { listen 80; server_name www.accp.com; charset utf-8; access_log logs/www.accp.com.access.log; location / { root /var/www/html/accp; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }4、重載Nginx服務(wù)

[root@localhost ~]# killall -s HUP nginx[root@localhost ~]# netstat -ntap | grep 80tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 6117/nginx: master5、測(cè)試網(wǎng)頁(yè),輸入www .kgc. com 與 www. accp. com兩個(gè)域名進(jìn)行訪問(wèn)


二、基于端口

1、配置虛擬主機(jī)
2、創(chuàng)建另一個(gè)端口的測(cè)試網(wǎng)頁(yè)

[root@localhost ~]# cd /var/www/html/[root@localhost html]# echo "this is kgc 8080 web" > kgc/index.html 3、編輯nginx.conf配置文件,僅修改監(jiān)聽(tīng)地址

[root@localhost html]# vim /usr/local/nginx/conf/nginx.confserver { listen 192.168.235.158:80; ##監(jiān)聽(tīng)主機(jī)的80端口 server_name www.kgc.com; charset utf-8; access_log logs/www.kgc.com.access.log; location / { root /var/www/html/kgc; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }server { listen 192.168.235.158:8080; ##監(jiān)聽(tīng)主機(jī)的8080端口 server_name www.kgc.com; charset utf-8; access_log logs/www.kgc.com.access.log; location / { root /var/www/html/kgc; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }4、重載Nginx服務(wù)

[root@localhost html]# killall -s HUP nginx[root@localhost html]# netstat -ntap | grep 80tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 41958/nginx: master5、測(cè)試網(wǎng)頁(yè),分別訪問(wèn)80端口的默認(rèn)網(wǎng)頁(yè)以及8080端口的網(wǎng)頁(yè)


三、基于IP

1、添加網(wǎng)卡,并規(guī)劃好IP
主機(jī)IP :192.168.235.158 ; 192.168.235.142
域名 :www . kgc . com ; www . accp . com
2、修改accp域名的區(qū)域數(shù)據(jù)文件配置

[root@localhost ~]# vim /var/named/accp.com.zone$TTL 1D@ IN SOA @ rname.invalid. ( 0 ; serial 1D ; refresh 1H ; retry 1W ; expire 3H ) ; minimum NS @ A 127.0.0.1www IN A 192.168.235.142##更改IP地址為 192.168.235.142[root@localhost ~]# systemctl restart named##重啟域名解析服務(wù)3、編輯nginx.conf配置文件

[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf##此段不做修改server { listen 192.168.235.158:80; server_name www.kgc.com; charset utf-8; access_log logs/www.kgc.com.access.log; location / { root /var/www/html/kgc; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }server { listen 192.168.235.142:80; ##修改本段監(jiān)聽(tīng)地址為192.168.234.142 server_name www.accp.com; charset utf-8; access_log logs/www.accp.com.access.log; location / { root /var/www/html/accp; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }4、重載Nginx服務(wù)

[root@localhost ~]# killall -s HUP nginx[root@localhost ~]# netstat -ntap | grep 80tcp 0 0 192.168.235.142:80 0.0.0.0:* LISTEN 7299/nginx: master tcp 0 0 192.168.235.158:80 0.0.0.0:* LISTEN 7299/nginx: master5、測(cè)試網(wǎng)頁(yè),分別輸入IP地址192.168.235.158和192.168.235.142進(jìn)行訪問(wèn)


更多干貨點(diǎn)我主頁(yè),或關(guān)注專(zhuān)欄查收。

本專(zhuān)欄所有文章均為杭州課工場(chǎng)學(xué)員投稿,如有問(wèn)題歡迎指出討論,未經(jīng)允許,禁止轉(zhuǎn)載!

關(guān)鍵詞:主機(jī),虛擬,工場(chǎng),培訓(xùn),杭州

74
73
25
news

版權(quán)所有? 億企邦 1997-2025 保留一切法律許可權(quán)利。

為了最佳展示效果,本站不支持IE9及以下版本的瀏覽器,建議您使用谷歌Chrome瀏覽器。 點(diǎn)擊下載Chrome瀏覽器
關(guān)閉