nginx.config
#user nobody;
worker_processes 4;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
server {
resolver 8.8.8.8; #dns解析地址
listen 89; #代理监听端口
proxy_connect;
proxy_connect_allow 443 563;
location / {
proxy_pass https://$host$request_uri; #设定https代理服务器的协议和地址
proxy_set_header HOST $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;
}
}
}
其中:
resolver 8.8.8.8; #dns解析地址
listen 89; #代理监听端口
proxy_connect;
proxy_connect_allow 443 563;
与
proxy_pass https://$host$request_uri; #设定https代理服务器的协议和地址
为重点配置,监听端口可调,其他配置按需添加
测试方式:
1. 客户机代理配置
环境变量里添加代理
vim /etc/profile
~
~
# 在文件末尾添加代理
#export https_proxy=正向代理IP:端口
export https_proxy=192.168.1.104:89
重新加载使配置文件生效
source /etc/profile
或
. /etc/profile
2. 临时代理
#curl -i --proxy 代理IP:端口 要访问域名
curl -i -k --proxy 192.168.1.104:89 https://www.baidu.com
友情提示
-
curl 命令get请求url中需传递多个参数时,需对 & 符号进行转译(&),若不进行转译则会出现参数丢失,仅保留第一个参数
-
实际项目中需在项目中增加代理操作,可参照:javaweb项目代理