使用nginx設置代理服務器
nginx可以利用其反向代理的功能來進行負載均衡的實現(xiàn),同時也可以使用其正向代理的功能設置代理服務器,比如在內網(wǎng)的環(huán)境中,在可以連接外網(wǎng)的機器上運行nginx作為代理服務器,其他機器通過設定此臺機器的IP和port即可通過其連接上網(wǎng),本文使用nginx官方鏡像,通過如下步驟即可簡單實現(xiàn)代理服務器。
Step 1: 啟動nginx
[root@devops ~]# docker run -p 8888:8888 --name proxy-nginx -d nginx c7baab8ea9da0a148aa9bcc1295a54391906f6be94efca7189df23ceecdbf714 [root@devops ~]#
Step 2: 設定nginx
進入容器中
[root@devops ~]# docker exec -it proxy-nginx sh
update apt-get
安裝ping/vi/ps:apt-get update; apt-get install procps vim inetutils-ping
設定nginx.conf
加入如下內容,即可實現(xiàn)最簡單的代理功能
resolver 8.8.8.8; server { listen 8888; location / { proxy_pass http://$http_host$request_uri; } }
其余信息均為nginx.conf的確認內容,未做修改
# 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: 設定客戶端
在客戶端設定服務器IP和上述的端口8888,即可通過改代理服務器連接網(wǎng)絡。
總結
以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作具有一定的參考學習價值,謝謝大家對腳本之家的支持。如果你想了解更多相關內容請查看下面相關鏈接
相關文章
詳解實現(xiàn)Nginx+Tomcat實現(xiàn)單IP、多域名、多站點的訪問
這篇文章主要介紹了詳解實現(xiàn)Nginx+Tomcat實現(xiàn)單IP、多域名、多站點的訪問的相關資料,這里提供實例幫助到大家實現(xiàn)改功能,希望能幫助到大家,需要的朋友可以參考下2017-08-08詳解Nginx反向代理WebSocket響應403的解決辦法
本篇文章主要介紹了詳解Nginx反向代理WebSocket響應403的解決辦法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-01-01