nginx可以利用其反向代理的功能來進(jìn)行負(fù)載均衡的實(shí)現(xiàn),同時(shí)也可以使用其正向代理的功能設(shè)置代理服務(wù)器,比如在內(nèi)網(wǎng)的環(huán)境中,在可以連接外網(wǎng)的機(jī)器上運(yùn)行nginx作為代理服務(wù)器,其他機(jī)器通過設(shè)定此臺(tái)機(jī)器的IP和port即可通過其連接上網(wǎng),本文使用nginx官方鏡像,通過如下步驟即可簡單實(shí)現(xiàn)代理服務(wù)器。
Step 1: 啟動(dòng)nginx
1
2
3
|
[root@devops ~]# docker run -p 8888:8888 --name proxy-nginx -d nginx c7baab8ea9da0a148aa9bcc1295a54391906f6be94efca7189df23ceecdbf714 [root@devops ~]# |
Step 2: 設(shè)定nginx
進(jìn)入容器中
[root@devops ~]# docker exec -it proxy-nginx sh
update apt-get
安裝ping/vi/ps:apt-get update; apt-get install procps vim inetutils-ping
設(shè)定nginx.conf
加入如下內(nèi)容,即可實(shí)現(xiàn)最簡單的代理功能
1
2
3
4
5
6
7
|
resolver 8.8 . 8.8 ; server { listen 8888 ; location / { proxy_pass http: //$http_host$request_uri; } } |
其余信息均為nginx.conf的確認(rèn)內(nèi)容,未做修改
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# cat nginx.conf user nginx; worker_processes 1; error_log /var/ log /nginx/error. log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/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 /var/ log /nginx/access. log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; #gzip on; resolver 8.8.8.8; server { listen 8888; location / { proxy_pass http: //$http_host$request_uri; } } include /etc/nginx/conf.d/*.conf; } # |
Step 4: 設(shè)定客戶端
在客戶端設(shè)定服務(wù)器IP和上述的端口8888,即可通過改代理服務(wù)器連接網(wǎng)絡(luò)。
總結(jié)
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,謝謝大家對(duì)服務(wù)器之家的支持。如果你想了解更多相關(guān)內(nèi)容請(qǐng)查看下面相關(guān)鏈接
原文鏈接:https://blog.csdn.net/liumiaocn/article/details/80502352