大佬教程收集整理的这篇文章主要介绍了CentOS7.X下-nginx配置正向代理支持https,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
本次测试使用的操作系统为:CentOS 7.2 x86 64位 最小化安装的操作系统,系统基础优化请参考:https://www.cnblogs.com/hei-ma/p/9506623.html
正向代理的Nginx安装正常安装就可以,没有特别的要求,
说明:
Nginx当正向代理的时候,通过代理访问https的网站会失败,而失败的原因是客户端同Nginx代理服务器之间建立连接失败,并非Nginx不能将https的请求转发出去。因此要解决的问题就是客户端如何同Nginx代理服务器之间建立起连接。有了这个思路之后,就可以很简单的解决问题。我们可以配置两个SERVER节点,一个处理http转发,另一个处理httpS转发,而客户端都通过http来访问代理,通过访问代理不同的端口,来区分http和httpS请求。
# @H_404_26@cat Nginx.conf # For @H_673_39@@H_404_26@more information on configuration,see: # @H_673_39@* Official English Documentation: http://@H_673_39@Nginx.org/en/docs/@H_673_39@ # * Official Russian Documentation: http://@H_673_39@Nginx.org/ru/docs/@H_673_39@ user Nginx; worker_processes auto; error_log @H_673_39@/var/log/Nginx/error.log; pid @H_673_39@/run/Nginx.pid; include @H_673_39@/usr/share/Nginx/modules/*@H_673_39@.conf; events { worker_connections 1024; } http { 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; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; include /etc/Nginx/mime.types; default_type application/octet-stream; include /etc/Nginx/conf.d/*.conf; #http proxy #这里位http的正向代理配置 server{ resolver 8.8.8.8; access_log /var/log/Nginx/access_proxy-80.log main; listen 80; LOCATIOn / { root html; index index.html index.htm; proxy_pass $scheR_944_11845@e://$host$request_uri; proxy_set_header HOST $http_host; proxy_buffers 256 4k; proxy_max_temp_file_size 0k; proxy_connect_timeout 30; proxy_send_timeout 60; proxy_read_timeout 60; proxy_next_upstream error timeout invalid_header http_502; } error_page 500 502 503 504 /50x.html; LOCATIOn = /50x.html { root html; } } #httpS proxy #这里为:https的正向代理配置 server{ resolver 8.8.8.8; access_log /var/log/Nginx/access_proxy-443.log main; listen 443; LOCATIOn / { root html; index index.html index.htm; proxy_pass https://$host$request_uri; proxy_buffers 256 4k; proxy_max_temp_file_size 0k; proxy_connect_timeout 30; proxy_send_timeout 60; proxy_read_timeout 60; proxy_next_upstream error timeout invalid_header http_502; } error_page 500 502 503 504 /50x.html; LOCATIOn = /50x.html { root html; } } }@H_673_39@
配置后重启Nginx,
然后我们来访问测试下:
测试机要求:
有独立的局域网地址,不可连通外网
1、如果访问http网站,可以直接这样的方式: curl --proxy proxy_server-ip:80 http://www.hehebo.com/
2、如果访问httpS网站,例如https://www.alipay.com,那么可以使用Nginx的httpS转发的server:
curl --proxy proxy_server:443 http://www.alipay.com
以上是大佬教程为你收集整理的CentOS7.X下-nginx配置正向代理支持https全部内容,希望文章能够帮你解决CentOS7.X下-nginx配置正向代理支持https所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。