學(xué)習(xí)主題:Nginx學(xué)習(xí)目標(biāo):1 掌握Nginx在Linux下的各種配置

2 掌握使用Nginx實現(xiàn)負(fù)載均衡,反向代理

對應(yīng)作業(yè)

Linux綁定多IP如何在Linux中綁定多IP?(寫出步驟)


一臺" />

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

15158846557 在線咨詢 在線咨詢
15158846557 在線咨詢
所在位置: 首頁 > 營銷資訊 > 網(wǎng)站運營 > Nginx學(xué)完了!!! ---Java133天學(xué)習(xí)

Nginx學(xué)完了!!! ---Java133天學(xué)習(xí)

時間:2023-07-14 13:27:01 | 來源:網(wǎng)站運營

時間:2023-07-14 13:27:01 來源:網(wǎng)站運營

Nginx學(xué)完了!!! ---Java133天學(xué)習(xí):第160次(Nginx)

學(xué)習(xí)主題:Nginx

學(xué)習(xí)目標(biāo):

1 掌握Nginx在Linux下的各種配置

2 掌握使用Nginx實現(xiàn)負(fù)載均衡,反向代理

對應(yīng)作業(yè)

  1. Linux綁定多IP
    1. 如何在Linux中綁定多IP?(寫出步驟)



  1. 一臺 Linux 服務(wù)器綁定兩個 ip:192.168.70.144、192.168.70.188 訪問不同的 ip 請求不同的 html 目錄,
即:

訪問 http://192.168.70.144 將訪問“html144”目錄下的 html 網(wǎng)頁

訪問 http://192.168.70.188 將訪問“html188”目錄下的 html 網(wǎng)頁




  1. Linux 操作系統(tǒng)允許綁定多 IP。使用 IP 別名的方式,在一塊物理網(wǎng)卡上可以綁定多個 lP 地址。這樣就能夠在使用單一網(wǎng)卡的同一個服務(wù)器上運行多個基于 IP 的虛擬主機。但是 在綁定多 IP 時需要將動態(tài)的 IP 分配方式修改為靜態(tài)的指定 IP



  1. cd /etc/sysconfig/network-scripts
IPADDR=192.168.10.144

NETMASK=255.255.255.0

GATEWAY=192.168.10.2

DNS1=114.114.114.114




  1. 將/etc/sysconfig/network-scripts/ifcfg-eth0 文件復(fù)制一份,命名為 ifcfg-eth0:1
修改其中內(nèi)容: DEVICE=eth0:1

IPADDR=192.168.70.188

其他項不用修改 重啟系統(tǒng)










  1. Nginx基于IP的虛擬主機配置
    1. 如何配置Nginx的基于IP訪問的虛擬主機?(寫出步驟)












user root;

worker_processes 1;




#error_log logs/error.log;

#error_log logs/error.log notice;

#error_log logs/error.log info;




#pid logs/nginx.pid;

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"';

#access_log logs/access.log main;

sendfile on;

#tcp_nopush on;

#keepalive_timeout 0;

keepalive_timeout 65;

#gzip on;

server {

listen 80;

server_name 192.168.193.129;

location / {

root html129;

index index.html index.htm;

}




error_page 500 502 503 504 /50x.html;

location = /50x.html {

root html;

}




}

server {

listen 80;

server_name 192.168.193.130;

location / {

root html130;

index index.html index.htm;

}

error_page 500 502 503 504 /50x.html;

location = /50x.html {

root html;

}




}




}




  1. Nginx基于端口的虛擬主機配置
    1. 如何配置Nginx的基于端口訪問的虛擬主機?(寫出步驟)






user root;

worker_processes 1;




#error_log logs/error.log;

#error_log logs/error.log notice;

#error_log logs/error.log info;




#pid logs/nginx.pid;







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"';




#access_log logs/access.log main;




sendfile on;

#tcp_nopush on;




#keepalive_timeout 0;

keepalive_timeout 65;




#gzip on;




server {

listen 80;

server_name 192.168.193.129;







location / {

root html129;

index index.html index.htm;

}




error_page 500 502 503 504 /50x.html;

location = /50x.html {

root html;

}




}







server {

listen 80;

server_name 192.168.193.130;







location / {

root html130;

index index.html index.htm;

}




error_page 500 502 503 504 /50x.html;

location = /50x.html {

root html;

}




}

#這里是配置端口的

server {

listen 4444;

server_name 192.168.193.129;







location / {

root html4444;

index index.html index.htm;

}




error_page 500 502 503 504 /50x.html;

location = /50x.html {

root html;

}




}

server {

listen 5555;

server_name 192.168.193.129;







location / {

root html5555;

index index.html index.htm;

}




error_page 500 502 503 504 /50x.html;

location = /50x.html {

root html;

}




}

}

重啟Nginx:

./nginx -s quit 關(guān)閉

./nginx 啟動

  1. Nginx基于域名的虛擬主機配置
    1. 如何配置Nginx的基于域名訪問的虛擬主機?(寫出步驟)



文件路徑:C:/Windows/System32/drivers/etc (獲取管理員權(quán)限否則不能修改)







配置Nginx(這里主要是server的配置)

#配置百度

server {

listen 80;

server_name www.baidu.com;

location / {

root htmlbaidu;

index index.html index.htm;

}

error_page 500 502 503 504 /50x.html;

location = /50x.html {

root html;

}

}

#配置淘寶

server {

listen 80;

server_name www.taobao.com;

location / {

root htmltaobao;

index index.html index.htm;

}

error_page 500 502 503 504 /50x.html;

location = /50x.html {

root html;

}

}




  1. Nginx反向代理-配置反向代理
    1. 如何通過Nginx配置服務(wù)的反向代理?(寫出步驟)_



2.1需求

安裝兩個 tomcat 服務(wù),通過 nginx 反向代理。 本案例中使用兩臺虛擬機演示。 tomcat 安裝到 192.168.70.143 環(huán)境中。端口為 8080 與 9090 Nginx 安裝在 192.168.70.144 環(huán)境中

2.2安裝環(huán)境

2.3安裝 tomcat







2.4配置 tomcat

2.4.1修改端口




2.4.2修改首頁內(nèi)容




2.5配置 Nginx 實現(xiàn)服務(wù)的反向代理

nginx.conf

user root; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events {

worker_connections 1024; } http {

include mime.types;

default_type application/octet-stream;

sendfile on;

keepalive_timeout 65;

upstream tomcat_server1{ server 192.168.70.143:8080;

}

upstream tomcat_server2{ server 192.168.70.143:9090;

}

server {

listen 80; #為虛擬機指定 IP 或者是域名

server_name test.bjsxt.com; #主要配置路由訪問信息

location / {

#用于指定訪問根目錄時,訪問虛擬主機的 web 目錄

proxy_pass http://tomcat_server1;

#在不指定訪問具體資源時,默認(rèn)的展示資源的列表 index index.html index.htm;

}

error_page 500 502 503 504 /50x.html;

location = /50x.html {

root html;

}

}

#一個 Server 就是一個虛擬主機

server {

listen 80; #為虛擬機指定 IP 或者是域名

server_name test.itbaizhan.cn; #主要配置路由訪問信息

location / {

#用于指定訪問根目錄時,訪問虛擬主機的 web 目錄

proxy_pass http://tomcat_server2;

#在不指定訪問具體資源時,默認(rèn)的展示資源的列表

index index.html index.htm;

}

error_page 500 502 503 504 /50x.html;

location = /50x.html {

root html;

}

} }







  1. Nginx反向代理-配置負(fù)載均衡
    1. 什么是負(fù)載均衡?



負(fù)載均衡建立在現(xiàn)有網(wǎng)絡(luò)結(jié)構(gòu)之上,它提供了一種廉價有效透明的方法擴展 網(wǎng)絡(luò)設(shè)備和服務(wù)器的帶寬、增加吞吐量、加強網(wǎng)絡(luò)數(shù)據(jù)處理能力、提高網(wǎng)絡(luò)的靈活性和可用性。

負(fù)載均衡,英文名稱為 Load Balance,其意思就是分?jǐn)偟蕉鄠€操作單元上 進(jìn)行執(zhí)行,例如 Web 服務(wù)器、FTP 服務(wù)器、企業(yè)關(guān)鍵應(yīng)用服務(wù)器和其它關(guān)鍵任務(wù) 服務(wù)器等,從而共同完成工作任務(wù)。

  1. Nginx中所支持的負(fù)載均衡策略有哪些?



輪詢(默認(rèn))

每個請求按時間順序逐一分配到不同的后端服務(wù)器,如果后 端服務(wù)器 down 掉,能自動剔除。

指定權(quán)重

指定輪詢幾率,weight 和訪問比率成正比,用于后端服務(wù)器 性能不均的情況。 upstream backserver { server 192.168.0.14 weight=10; server 192.168.0.15 weight=10; }




  1. Nginx中默認(rèn)的負(fù)載均衡策略是什么?



輪詢(默認(rèn))

  1. 如何在Nginx中指定權(quán)重?



指定輪詢幾率,weight 和訪問比率成正比,用于后端服務(wù)器 性能不均的情況。 upstream backserver { server 192.168.0.14 weight=10; server 192.168.0.15 weight=10; }

  1. Nginx反向代理-HTTP協(xié)議代理
    1. 如何通過Nginx解決上傳圖片后無法回顯的問題?
明天再改.

關(guān)鍵詞:學(xué)習(xí)

74
73
25
news

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

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