Ariya Hidayat
PhantomJS maintainer
原生nginx只支持http正向代理.
为了nginx支持https正向代理,可以打ngx_http_proxy_connect_module-master补丁+ ssl模块支持.
win10真机 + debian8.8虚拟机
root@localhost:~# cat /etc/network/interfaces
auto eth0
allow-hotplug eth0
iface eth0 inet static
address 192.168.11.200
netmask 255.255.255.0
gateway 192.168.11.2
reboot
su - root
mkdir -p /home/test_nginx/
cd /home/test_nginx/
ngx_http_proxy_connect_module-master补丁支持的最新的nginx版本为nginx-1.15.2
wget http://nginx.org/download/nginx-1.15.2.tar.gz
tar -xzvf ./nginx-1.15.2.tar.gz
https://github.com/chobits/ngx_http_proxy_connect_module
将下载好的ngx_http_proxy_connect_module-master.zip上传到 /home/test_nginx/
aptitude install unzip
unzip ./ngx_http_proxy_connect_module-master.zip
cd /home/test_nginx/nginx-1.15.2
./configure --help | grep ssl
aptitude update
aptitude search PCRE
aptitude install libpcre3 libpcre3-dev
aptitude search ssl
aptitude install libssl-dev
./configure --add-module=/home/test_nginx/ngx_http_proxy_connect_module-master --with-http_ssl_module
Configuration summary
+ using system PCRE library
+ using system OpenSSL library
+ using system zlib library
nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/nginx/sbin/nginx"
nginx modules path: "/usr/local/nginx/modules"
nginx configuration prefix: "/usr/local/nginx/conf"
nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
nginx pid file: "/usr/local/nginx/logs/nginx.pid"
nginx error log file: "/usr/local/nginx/logs/error.log"
nginx http access log file: "/usr/local/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"
注意 nginx-1.15.2对应的补丁为proxy_connect_rewrite_1015.patch,可以先看ngx_http_proxy_connect_module-master的readme
patch -d /home/test_nginx/nginx-1.15.2/ -p 1 < /home/test_nginx/ngx_http_proxy_connect_module-master/patch/proxy_connect_rewrite_1015.patch
补丁的结果很干净。
如果补丁不对,会由错误提示信息.
patching file src/http/ngx_http_core_module.c
patching file src/http/ngx_http_parse.c
patching file src/http/ngx_http_request.c
patching file src/http/ngx_http_request.h
patching file src/http/ngx_http_variables.c
make
make install
root@localhost:/home/test_nginx/nginx-1.15.2# /usr/local/nginx/sbin/nginx -h
nginx version: nginx/1.15.2
Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives]
Options:
-?,-h : this help
-v : show version and exit
-V : show version and configure options then exit
-t : test configuration and exit
-T : test configuration, dump it and exit
-q : suppress non-error messages during configuration testing
-s signal : send signal to a master process: stop, quit, reopen, reload
-p prefix : set prefix path (default: /usr/local/nginx/)
-c filename : set configuration file (default: conf/nginx.conf)
-g directives : set global directives out of configuration file
root@localhost:/home/test_nginx/nginx-1.15.2# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.15.2
built by gcc 4.9.2 (Debian 4.9.2-10)
built with OpenSSL 1.0.1t 3 May 2016
TLS SNI support enabled
configure arguments: --add-module=/home/test_nginx/ngx_http_proxy_connect_module-master --with-http_ssl_module
find / -name 'nginx'
root@localhost:/home/test_nginx/nginx-1.15.2# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
这个配置文件就用ngx_http_proxy_connect_module-master自带的配置文件
/usr/local/nginx/sbin/nginx -s stop
cat /usr/local/nginx/conf/nginx.conf
lsof -i:8080
root@localhost:/home/test_nginx/nginx-1.15.2# cat /usr/local/nginx/conf/nginx.conf
# @file /usr/local/nginx/conf/nginx.conf
worker_processes 1;
error_log logs/error.log;
error_log logs/error.log notice;
error_log logs/error.log info;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 8080;
# dns resolver used by forward proxying
resolver 8.8.8.8;
# forward proxy for CONNECT request
proxy_connect;
proxy_connect_allow 443 563;
proxy_connect_connect_timeout 10s;
proxy_connect_read_timeout 10s;
proxy_connect_send_timeout 10s;
# forward proxy for non-CONNECT request
location / {
proxy_pass http://$host;
proxy_set_header Host $host;
}
}
}
root@localhost:/home/test_nginx/nginx-1.15.2# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
root@localhost:/home/test_nginx/nginx-1.15.2# /usr/local/nginx/sbin/nginx -s stop
nginx: [error] invalid PID number "" in "/usr/local/nginx/logs/nginx.pid"
root@localhost:/home/test_nginx/nginx-1.15.2# /usr/local/nginx/sbin/nginx
aptitude search curl
aptitude install curl
curl https://github.com/ -v -x 192.168.11.200:8080 >& /home/test_nginx.log
查看日志,可以看到https正向代理已经成功
* Hostname was NOT found in DNS cache
* Trying 192.168.11.200...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Connected to 192.168.11.200 (192.168.11.200) port 8080 (#0)
* Establish HTTP proxy tunnel to github.com:443
> CONNECT github.com:443 HTTP/1.1
> Host: github.com:443
> User-Agent: curl/7.38.0
> Proxy-Connection: Keep-Alive
>
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0< HTTP/1.1 200 Connection Established
< Proxy-agent: nginx
<
* Proxy replied OK to CONNECT request
* successfully set certificate verify locations:
* CAfile: none
CApath: /etc/ssl/certs
* SSLv3, TLS handshake, Client hello (1):
} [data not shown]
* SSLv3, TLS handshake, Server hello (2):
{ [data not shown]
* SSLv3, TLS handshake, CERT (11):
{ [data not shown]
* SSLv3, TLS handshake, Server key exchange (12):
{ [data not shown]
* SSLv3, TLS handshake, Server finished (14):
{ [data not shown]
* SSLv3, TLS handshake, Client key exchange (16):
} [data not shown]
* SSLv3, TLS change cipher, Client hello (1):
} [data not shown]
* SSLv3, TLS handshake, Finished (20):
} [data not shown]
* SSLv3, TLS change cipher, Client hello (1):
{ [data not shown]
* SSLv3, TLS handshake, Finished (20):
{ [data not shown]
* SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
* Server certificate:
* subject: businessCategory=Private Organization; 1.3.6.1.4.1.311.60.2.1.3=US; 1.3.6.1.4.1.311.60.2.1.2=Delaware; serialNumber=5157550; C=US; ST=California; L=San Francisco; O=GitHub, Inc.; CN=github.com
* start date: 2018-05-08 00:00:00 GMT
* expire date: 2020-06-03 12:00:00 GMT
* subjectAltName: github.com matched
* issuer: C=US; O=DigiCert Inc; OU=www.digicert.com; CN=DigiCert SHA2 Extended Validation Server CA
* SSL certificate verify ok.
> GET / HTTP/1.1
> User-Agent: curl/7.38.0
> Host: github.com
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Wed, 28 Nov 2018 11:12:35 GMT
< Content-Type: text/html; charset=utf-8
< Transfer-Encoding: chunked
* Server GitHub.com is not blacklisted
< Server: GitHub.com
< Status: 200 OK
< Cache-Control: no-cache
< Vary: X-PJAX
< Set-Cookie: has_recent_activity=1; path=/; expires=Wed, 28 Nov 2018 12:12:35 -0000
< Set-Cookie: logged_in=no; domain=.github.com; path=/; expires=Sun, 28 Nov 2038 11:12:35 -0000; secure; HttpOnly
< Set-Cookie: _gh_sess=V3M1eUZQK1QvSXozOUh4dE50Vm8vL21NWFZwbTdQMzdWZitpa3VxK1hFZm9tOTNJbVZYVUhFaFdtMHEwTUM3VnBiWkpJRjFMRWNITWtZN3c2b1AybXlHdjc3ZzlpUHNLNU9BdSs3YmZxbXlhRmhyWXZNY0ZFN2lMcXBxay94T0FwMmFyOUpSbkNtSDlkNzFDMmppSXhvMVR0OHN4REoyM3NCUEpEblUzOEdJc2UvRXhkSmQxVDlpdVVlMTRZVE1DTXNXVGJkVGRuNUFZUHZKVklJQk1TZz09LS1ZMkR1WU9NZTRnd000YzNIU3RIZ0RnPT0%3D--4be4facb8e3eeaa9be9a99c2eb5543044a8c6abd; path=/; secure; HttpOnly
< X-Request-Id: e9423279-5ea2-481a-aead-ce7b2515a81b
< Strict-Transport-Security: max-age=31536000; includeSubdomains; preload
< X-Frame-Options: deny
< X-Content-Type-Options: nosniff
< X-XSS-Protection: 1; mode=block
< Referrer-Policy: origin-when-cross-origin, strict-origin-when-cross-origin
< Expect-CT: max-age=2592000, report-uri="https://api.github.com/_private/browser/errors"
0 0 0 0 0 0 0 0 --:--:-- 0:00:01 --:--:-- 0< Content-Security-Policy: default-src 'none'; base-uri 'self'; block-all-mixed-content; connect-src 'self' uploads.github.com status.github.com collector.githubapp.com api.github.com www.google-analytics.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com wss://live.github.com; font-src assets-cdn.github.com; form-action 'self' github.com gist.github.com; frame-ancestors 'none'; frame-src render.githubusercontent.com; img-src 'self' data: assets-cdn.github.com identicons.github.com collector.githubapp.com github-cloud.s3.amazonaws.com *.githubusercontent.com; manifest-src 'self'; media-src 'none'; script-src assets-cdn.github.com; style-src 'unsafe-inline' assets-cdn.github.com
< Vary: Accept-Encoding
< X-GitHub-Request-Id: D276:1049:25AD1D1:35EE509:5BFE7822
<
{ [data not shown]
The world’s leading software development platform · GitHub
Built for developers
GitHub is a development platform inspired by the way you work. From open source to business, you can host and review code, manage projects, and build software alongside 31 million developers.
Try GitHub Enterprise
Use GitHub on-premises with your own servers or in a private cloud with GitHub Enterprise. Improve your developer efficiency with flexible deployment options, centralized permissions, hundreds of integrations, technical support, and more.
More than 2.1 million businesses and organizations use GitHub
GitHub for teams
A better way to work together
GitHub brings teams together to work through problems, move ideas forward, and learn from each other along the way.
Write better code
Collaboration makes perfect. The conversations and code reviews that happen in Pull Requests help your team share the weight of your work and improve the software you build. Learn about code review.
Manage your chaos
Take a deep breath. On GitHub, project management happens in Issues and Projects, right alongside your code. All you have to do is mention a teammate to get them involved. Learn about project management.
Find the right tools
Browse and buy apps from GitHub Marketplace with your GitHub account. Find the tools you like or discover new favorites—then start using them in minutes. Learn about integrations.
Security and administration
Boxes? Check.
We worry about your administrative and security needs so you don’t have to. From flexible hosting to authentication options, GitHub can help you meet your team’s requirements.
How GitHub works for businesses →
See how GitHub works for businesses →
Code security
Prevent problems before they happen. Protected branches, signed commits, and required status checks protect your work and help you maintain a high standard for your code.
Access controlled
Encourage teams to work together while limiting access to those who need it with granular permissions and authentication through SAML/SSO and LDAP.
Hosted where you need it
Securely and reliably host your work on GitHub.com. Or, deploy GitHub Enterprise on your own servers or in a private cloud using Amazon Web Services, Azure or Google Cloud Platform.
Compare plans →
Contact Sales for more information →
Integrations
Build on GitHub
Customize your process with GitHub apps and an intuitive API. Integrate the tools you already use or discover new favorites to create a happier, more efficient way of working.
Sometimes, there’s more than one tool for the job. Why not try something new?
Community
Welcome home,
developers
GitHub is home to the world’s largest community of developers and their projects...
Ariya Hidayat
PhantomJS maintainer
Russell Keith-Magee
PyBee maintainer
MailChimp
Marketing customer
Kris Nova
Kubernetes/kops maintainer
Evan You
Vue maintainer
Mapbox
Software customer
Jess Frazelle
Kubernetes, previously Docker maintainer
...whether you’re making your first commit or sending a Rover to Mars, there’s room for you here, too.
96M*
repositories worldwide
GitHub’s users create and maintain influential technologies alongside the world’s largest open source community.
31M*
developers worldwide
Developers use GitHub for personal projects, from experimenting with new programming languages to hosting their life’s work.
2.1M*
businesses and organizations worldwide
Businesses of all sizes use GitHub to support their development process and to securely build software.
* As of October 2018
Get started for free — join the millions of developers already using GitHub to share their code, work together, and build amazing things.
Press h to open a hovercard with more details.