当前位置:   article > 正文

nginx系列-使用 Nginx 搭建公网代理服务器_nginx搭建代理服务器

nginx搭建代理服务器

准备工作

节点IP描述
server 192.168.0.3可访问公网
client192.168.0.4不可访问公网

1. nginx安装

  1. $ yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel patch pcre pcre-devel
  2. $ wget http://nginx.org/download/nginx-1.16.0.tar.gz
  3. $ git clone https://github.com/chobits/ngx_http_proxy_connect_module.git
  4. $ tar xf nginx-1.16.0.tar.gz -C /usr/local/src/
  5. $ cd /usr/local/src/nginx-1.16.0/
  6. $ patch -p1 < /root/ngx_http_proxy_connect_module/patch/proxy_connect_rewrite_101504.patch
  7. #此处proxy_connect_module选择与nginx版本有关
  8. $ ./configure --add-module=/root/ngx_http_proxy_connect_module/
  9. $ make -j 4
  10. #我这里是4核的cpu
  11. $ make install

2. 代理 nginx 服务器配置

  1. worker_processes 2;
  2. events {
  3. worker_connections 1024;
  4. }
  5. http {
  6. include mime.types;
  7. default_type application/octet-stream;
  8. sendfile on;
  9. keepalive_timeout 65;
  10. resolver 114.114.114.114;
  11. server {
  12. listen 6666;
  13. proxy_connect;
  14. location / {
  15. proxy_pass $scheme://$host$request_uri;
  16. }
  17. }
  18. server {
  19. listen 8443;
  20. # dns resolver used by forward proxying
  21. resolver 114.114.114.114;
  22. # forward proxy for CONNECT request
  23. proxy_connect;
  24. proxy_connect_allow 443 563;
  25. proxy_connect_connect_timeout 10s;
  26. proxy_connect_read_timeout 10s;
  27. proxy_connect_send_timeout 10s;
  28. # forward proxy for non-CONNECT request
  29. location / {
  30. proxy_pass http://$host;
  31. proxy_set_header Host $host;
  32. }
  33. }
  34. server {
  35. resolver 8.8.8.8;
  36. listen 8080;
  37. location / {
  38. proxy_pass http://$http_host$request_uri;
  39. proxy_set_header HOST $http_host;
  40. proxy_buffers 256 4k;
  41. proxy_max_temp_file_size 0k;
  42. proxy_connect_timeout 30;
  43. proxy_send_timeout 60;
  44. proxy_read_timeout 60;
  45. proxy_next_upstream error timeout invalid_header http_502;
  46. }
  47. }
  48. }
  • 8080端口为http代理端口
  • 8443端口为https代理

3. 客户端配置代理

  1. $ vim /etc/profile
  2. export http_proxy=http://192.168.0.3:8080/
  3. export https_proxy=https://192.168.0.3:8443/
  4. $ source /etc/profile

测试

  1. # http测试
  2. $ curl http://www.baidu.com
  3. # https 测试
  4. $ curl https://www.baidu.com

4. wget代理配置

  1. $ vim /etc/wgetrc
  2. http_proxy=http://192.168.0.3:8080/
  3. https_proxy=https://192.168.0.3:8443/
  4. $ source /etc/wgetrc

分别使用wget http://xxxx和wget https://xxxx测试下载即可。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/690092
推荐阅读
相关标签
  

闽ICP备14008679号