使用nginx设置代理服务器

今天小编就为大家分享一篇关于使用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,即可通过改代理服务器连接网络。

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对html中文网的支持。如果你想了解更多相关内容请查看下面相关链接

以上就是使用nginx设置代理服务器的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » 服务器