使用nginx设置代理服务器
nginx可以利用其反向代理的功能来进行负载均衡的实现,同时也可以使用其正向代理的功能设置代理服务器,比如在内网的环境中,在可以连接外网的机器上运行nginx作为代理服务器,其他机器通过设定此台机器的IP和port即可通过其连接上网,本文使用nginx官方镜像,通过如下步骤即可简单实现代理服务器。
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
加入如下内容,即可实现最简单的代理功能
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,即可通过改代理服务器连接网络。
相关推荐
windle 2020-10-29
superyu 2020-09-10
nginxs 2020-11-14
Guanjs0 2020-11-13
小木兮子 2020-11-11
yserver 2020-11-11
ssihc0 2020-11-11
windle 2020-11-10
HanksWang 2020-11-10
liuchen0 2020-11-10
Freshairx 2020-11-10
ccschan 2020-11-10
liwf 2020-11-10
Guanjs0 2020-11-09
AderStep 2020-11-09
zrtlin 2020-11-09