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

15158846557 在線咨詢 在線咨詢
15158846557 在線咨詢
所在位置: 首頁 > 營銷資訊 > 網(wǎng)站運(yùn)營 > nginx虛擬主機(jī)配置

nginx虛擬主機(jī)配置

時(shí)間:2023-07-17 10:00:02 | 來源:網(wǎng)站運(yùn)營

時(shí)間:2023-07-17 10:00:02 來源:網(wǎng)站運(yùn)營

nginx虛擬主機(jī)配置:什么是虛擬主機(jī)? 虛擬主機(jī)是一種特殊的軟硬件技術(shù),它可以將網(wǎng)絡(luò)上的每一臺(tái)計(jì)算機(jī)分成多個(gè)虛擬主機(jī),每個(gè)虛擬主機(jī)可以獨(dú)立對(duì)外提供www服務(wù),這樣就可以實(shí)現(xiàn)一臺(tái)主機(jī)對(duì)外提供多個(gè)web服務(wù),每個(gè)虛擬主機(jī)之間是獨(dú)立的,互不影響。

nginx可以實(shí)現(xiàn)虛擬主機(jī)的配置,nginx支持三種類型的虛擬主機(jī)配置。 1、基于域名的虛擬主機(jī) (server_name來區(qū)分虛擬主機(jī)——應(yīng)用:外部網(wǎng)站) 2、基于ip的虛擬主機(jī), (一塊主機(jī)綁定多個(gè)ip地址) 3、基于端口的虛擬主機(jī) (端口來區(qū)分虛擬主機(jī)——應(yīng)用:公司內(nèi)部網(wǎng)站,外部網(wǎng)站的管理后臺(tái))

1、 基于域名的虛擬主機(jī)

1、配置通過域名區(qū)分的虛擬機(jī)

[root@localhost ~]# cat /etc/nginx/nginx.confworker_processes 4;?#error_log logs/error.log;worker_rlimit_nofile 102400;??events { worker_connections 1024;}??http { include mime.types; default_type application/octet-stream; server { listen 80; server_name web.testpm.com; location / { root /var/www/nginx/; index index.html index.htm; limit_rate 2k; } } server { listen 80; server_name web.1000phone.com; location / { root /1000phone/html; index index.html index.htm; } }}2、 為 域名為 http://web.1000phone.com 的虛擬機(jī),創(chuàng)建 index 文件

[root@localhost ~]# mkdir -p /1000phone/html[root@localhost ~]# vim /1000phone/html/index.html<html><p>this is my 1000phone</p></html>3、重新加載配置文件

# 如果編譯安裝的執(zhí)行[root@nginx]# /usr/local/nginx/sbin/nginx -s reload# 如果 yum 安裝的執(zhí)行[root@nginx]# nginx -s reload4、客戶端配置路由映射 在 C:/Windows/System32/drivers/etc/hosts 文件中添加兩行(linux:/etc/hosts)

10.0.105.199 web.testpm.com10.0.105.199 web.1000phone.com5、 測(cè)試訪問

瀏覽器輸入:http://web.testpm.com/

瀏覽器輸入:http://web.1000phone.com/

2、 基于ip的虛擬主機(jī)

[root@localhost ~]# ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:17:f1:af brd ff:ff:ff:ff:ff:ff inet 10.0.105.199/24 brd 10.0.105.255 scope global dynamic ens33 valid_lft 81438sec preferred_lft 81438sec inet6 fe80::9d26:f3f0:db9c:c9be/64 scope link valid_lft forever preferred_lft forever[root@localhost ~]# ifconfig ens33:1 10.0.105.201/24[root@localhost ~]# ifconfigens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 10.0.105.199 netmask 255.255.255.0 broadcast 10.0.105.255 inet6 fe80::9d26:f3f0:db9c:c9be prefixlen 64 scopeid 0x20<link> ether 00:0c:29:17:f1:af txqueuelen 1000 (Ethernet) RX packets 9844 bytes 1052722 (1.0 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 5567 bytes 886269 (865.4 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0?ens33:1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 10.0.105.201 netmask 255.255.255.0 broadcast 10.0.105.255 ether 00:0c:29:17:f1:af txqueuelen 1000 (Ethernet)?2、配置通過ip區(qū)分的虛擬機(jī)[root@localhost ~]# cat /etc/nginx/nginx.confuser root;worker_processes 4;?#error_log logs/error.log;worker_rlimit_nofile 102400;??events { worker_connections 1024;}??http { include mime.types; default_type application/octet-stream;? log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"';? server { listen 10.0.105.199:80; server_name web.testpm.com; location / { root /var/www/nginx/; index index.html index.htm; limit_rate 2k; } server { listen 10.0.105.201:80; server_name web.testpm.com; location / { root /1000phone/html/; index index.html index.htm; } }}3、重新加載配置文件[root@localhost ~]# /usr/local/nginx/sbin/nginx -s reload4、 測(cè)試訪問瀏覽器輸入:http://10.0.105.199瀏覽器輸入:http://10.0.105.2015、補(bǔ)充-- 刪除綁定的vip[root@localhost ~]# ifconfig ens33:1 10.0.105.201/24 down重啟一下nginx[root@localhost ~]# systemctl restart nginx3、 基于端口的虛擬主機(jī)

[root@localhost ~]# cat /etc/nginx/nginx.confuser root;worker_processes 4;?worker_rlimit_nofile 102400;??events { worker_connections 1024;}??http { include mime.types; default_type application/octet-stream;? log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"';?? sendfile on;? keepalive_timeout 65;?? server { listen 80; server_name web.testpm.com; location / { root /var/www/nginx/; index index.html index.htm; limit_rate 2k; } server { listen 8080; server_name web.1000phone.com; location / { root /1000phone/html/; index index.html index.htm; } }}重新加載配置文件:[root@localhost ~]# /usr/local/nginx/sbin/nginx -s reload測(cè)試訪問:瀏覽器輸入:http://web.testpm.com/瀏覽器輸入:http://web.1000phone.com:8080

關(guān)鍵詞:配置,主機(jī),虛擬

74
73
25
news

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

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