Oracle:使用nginx做为代理访问
nginx 必须启用 启用 --with-stream 模块。
可下载源码编译。
nginx.conf的配置:
worker_processes ; events {
worker_connections ;
} stream {
server{
listen so_keepalive=on;
proxy_pass 10.1.101.3:;
proxy_timeout 72h;
}
}
~
更一般的写法:
worker_processes ; events {
worker_connections ;
} stream {
upstream oracle{
server 10.1.101.3:;
}
server {
listen ;
proxy_pass oracle;
}
}
附录:官方改模块说明文档
Download the Complete NGINX Cookbook
Module ngx_stream_core_module
The ngx_stream_core_module
module is available since version 1.9.0. This module is not built by default, it should be enabled with the --with-stream
configuration parameter.
Example Configuration
worker_processes auto; error_log /var/log/nginx/error.log info; events {
worker_connections 1024;
} stream {
upstream backend {
hash $remote_addr consistent; server backend1.example.com:12345 weight=5;
server 127.0.0.1:12345 max_fails=3 fail_timeout=30s;
server unix:/tmp/backend3;
} upstream dns {
server 192.168.0.1:53535;
server dns.example.com:53;
} server {
listen 12345;
proxy_connect_timeout 1s;
proxy_timeout 3s;
proxy_pass backend;
} server {
listen 127.0.0.1:53 udp reuseport;
proxy_timeout 20s;
proxy_pass dns;
} server {
listen [::1]:12345;
proxy_pass unix:/tmp/stream.socket;
}
}
Directives
Syntax: | listen |
---|---|
Default: | — |
Context: | server |
Sets the address
and port
for the socket on which the server will accept connections. It is possible to specify just the port. The address can also be a hostname, for example:
listen 127.0.0.1:12345;
listen *:12345;
listen 12345; # same as *:12345
listen localhost:12345;
IPv6 addresses are specified in square brackets:
listen [::1]:12345;
listen [::]:12345;
UNIX-domain sockets are specified with the “unix:
” prefix:
listen unix:/var/run/nginx.sock;
The ssl
parameter allows specifying that all connections accepted on this port should work in SSL mode.
The udp
parameter configures a listening socket for working with datagrams (1.9.13).
The proxy_protocol
parameter (1.11.4) allows specifying that all connections accepted on this port should use the PROXY protocol.
The PROXY protocol version 2 is supported since version 1.13.11.
The listen
directive can have several additional parameters specific to socket-related system calls.
backlog
=number
- sets the
backlog
parameter in thelisten()
call that limits the maximum length for the queue of pending connections (1.9.2). By default,backlog
is set to -1 on FreeBSD, DragonFly BSD, and macOS, and to 511 on other platforms. rcvbuf
=size
- sets the receive buffer size (the
SO_RCVBUF
option) for the listening socket (1.11.13). sndbuf
=size
- sets the send buffer size (the
SO_SNDBUF
option) for the listening socket (1.11.13). bind
- this parameter instructs to make a separate
bind()
call for a given address:port pair. The fact is that if there are severallisten
directives with the same port but different addresses, and one of thelisten
directives listens on all addresses for the given port (*:
port
), nginx willbind()
only to*:
port
. It should be noted that thegetsockname()
system call will be made in this case to determine the address that accepted the connection. If theipv6only
orso_keepalive
parameters are used then for a givenaddress
:port
pair a separatebind()
call will always be made. ipv6only
=on
|off
- this parameter determines (via the
IPV6_V6ONLY
socket option) whether an IPv6 socket listening on a wildcard address[::]
will accept only IPv6 connections or both IPv6 and IPv4 connections. This parameter is turned on by default. It can only be set once on start. reuseport
- this parameter (1.9.1) instructs to create an individual listening socket for each worker process (using the
SO_REUSEPORT
socket option on Linux 3.9+ and DragonFly BSD, orSO_REUSEPORT_LB
on FreeBSD 12+), allowing a kernel to distribute incoming connections between worker processes. This currently works only on Linux 3.9+, DragonFly BSD, and FreeBSD 12+ (1.15.1).Inappropriate use of this option may have its security implications.
so_keepalive
=on
|off
|[keepidle
]:[keepintvl
]:[keepcnt
]- this parameter configures the “TCP keepalive” behavior for the listening socket. If this parameter is omitted then the operating system’s settings will be in effect for the socket. If it is set to the value “
on
”, theSO_KEEPALIVE
option is turned on for the socket. If it is set to the value “off
”, theSO_KEEPALIVE
option is turned off for the socket. Some operating systems support setting of TCP keepalive parameters on a per-socket basis using theTCP_KEEPIDLE
,TCP_KEEPINTVL
, andTCP_KEEPCNT
socket options. On such systems (currently, Linux 2.4+, NetBSD 5+, and FreeBSD 9.0-STABLE), they can be configured using thekeepidle
,keepintvl
, andkeepcnt
parameters. One or two parameters may be omitted, in which case the system default setting for the corresponding socket option will be in effect. For example,so_keepalive=30m::10
will set the idle timeout (
TCP_KEEPIDLE
) to 30 minutes, leave the probe interval (TCP_KEEPINTVL
) at its system default, and set the probes count (TCP_KEEPCNT
) to 10 probes.
Different servers must listen on different address
:port
pairs.
Syntax: | preread_buffer_size |
---|---|
Default: |
preread_buffer_size 16k; |
Context: | stream , server |
This directive appeared in version 1.11.5.
Specifies a size
of the preread buffer.
Syntax: | preread_timeout |
---|---|
Default: |
preread_timeout 30s; |
Context: | stream , server |
This directive appeared in version 1.11.5.
Specifies a timeout
of the preread phase.
Syntax: | proxy_protocol_timeout |
---|---|
Default: |
proxy_protocol_timeout 30s; |
Context: | stream , server |
This directive appeared in version 1.11.4.
Specifies a timeout
for reading the PROXY protocol header to complete. If no entire header is transmitted within this time, the connection is closed.
Syntax: | resolver |
---|---|
Default: | — |
Context: | stream , server |
This directive appeared in version 1.11.3.
Configures name servers used to resolve names of upstream servers into addresses, for example:
resolver 127.0.0.1 [::1]:5353;
An address can be specified as a domain name or IP address, and an optional port. If port is not specified, the port 53 is used. Name servers are queried in a round-robin fashion.
By default, nginx will look up both IPv4 and IPv6 addresses while resolving. If looking up of IPv6 addresses is not desired, the ipv6=off
parameter can be specified.
By default, nginx caches answers using the TTL value of a response. The optional valid
parameter allows overriding it:
resolver 127.0.0.1 [::1]:5353 valid=30s;
Before version 1.11.3, this directive was available as part of our commercial subscription.
Syntax: | resolver_timeout |
---|---|
Default: |
resolver_timeout 30s; |
Context: | stream , server |
This directive appeared in version 1.11.3.
Sets a timeout for name resolution, for example:
resolver_timeout 5s;
Before version 1.11.3, this directive was available as part of our commercial subscription.
Syntax: | server { ... } |
---|---|
Default: | — |
Context: | stream |
Sets the configuration for a server.
Syntax: | stream { ... } |
---|---|
Default: | — |
Context: | main |
Provides the configuration file context in which the stream server directives are specified.
Syntax: | tcp_nodelay |
---|---|
Default: |
tcp_nodelay on; |
Context: | stream , server |
This directive appeared in version 1.9.4.
Enables or disables the use of the TCP_NODELAY
option. The option is enabled for both client and proxied server connections.
Syntax: | variables_hash_bucket_size |
---|---|
Default: |
variables_hash_bucket_size 64; |
Context: | stream |
This directive appeared in version 1.11.2.
Sets the bucket size for the variables hash table. The details of setting up hash tables are provided in a separate document.
Syntax: | variables_hash_max_size |
---|---|
Default: |
variables_hash_max_size 1024; |
Context: | stream |
This directive appeared in version 1.11.2.
Sets the maximum size
of the variables hash table. The details of setting up hash tables are provided in a separate document.
Embedded Variables
The ngx_stream_core_module
module supports variables since 1.11.2.
$binary_remote_addr
- client address in a binary form, value’s length is always 4 bytes for IPv4 addresses or 16 bytes for IPv6 addresses
$bytes_received
- number of bytes received from a client (1.11.4)
$bytes_sent
- number of bytes sent to a client
$connection
- connection serial number
$hostname
- host name
$msec
- current time in seconds with the milliseconds resolution
$nginx_version
- nginx version
$pid
- PID of the worker process
$protocol
- protocol used to communicate with the client:
TCP
orUDP
(1.11.4) $proxy_protocol_addr
- client address from the PROXY protocol header, or an empty string otherwise (1.11.4)
The PROXY protocol must be previously enabled by setting the
proxy_protocol
parameter in the listen directive. $proxy_protocol_port
- client port from the PROXY protocol header, or an empty string otherwise (1.11.4)
The PROXY protocol must be previously enabled by setting the
proxy_protocol
parameter in the listen directive. $remote_addr
- client address
$remote_port
- client port
$server_addr
- an address of the server which accepted a connection
Computing a value of this variable usually requires one system call. To avoid a system call, the listen directives must specify addresses and use the
bind
parameter. $server_port
- port of the server which accepted a connection
$session_time
- session duration in seconds with a milliseconds resolution (1.11.4);
$status
- session status (1.11.4), can be one of the following:
200
- session completed successfully
400
- client data could not be parsed, for example, the PROXY protocol header
403
- access forbidden, for example, when access is limited for certain client addresses
500
- internal server error
502
- bad gateway, for example, if an upstream server could not be selected or reached.
503
- service unavailable, for example, when access is limited by the number of connections
$time_iso8601
- local time in the ISO 8601 standard format
$time_local
- local time in the Common Log Format
测试可行
Oracle:使用nginx做为代理访问的更多相关文章
- 使用nginx做反向代理
很多同学喜欢用nginx做反向代理访问某些网站,原因大家都懂的,今天老高记录一下如何使用nginx做反向代理以及如何配置和优化nginx的反向代理. 准备工作 首先,你需要一个稳定的国外的便宜的VPS ...
- 用nginx做反向代理来访问防外链图片
用nginx做反向代理来访问防外链图片 女儿的博客从新浪搬到wordpress后,发现原来博客上链接的新浪相册的图片都不能访问了,一年的博客内容,一个个去重新上传图片,修正链接也是个大工程.还是得先想 ...
- nginx做正向代理(Centos7,支持http和https)
默认的情况下,使用nginx做正向代理可以解析http请求, 对于诸如baidu.com这样的https请求,nginx默认并不支持,不过我们可以借助第三方模块来实现. 1.先说默认情况下的代理配置 ...
- 利用nginx做反向代理解决前端跨域问题
最近朋友再群里提了一个问题,他们公司给他提供了一个获取数据的接口,在浏览器访问这个接口能获取到json数据,但是放在项目里使用ajax就产生了跨域问题,一般这个需要提供接口的后台方面需要做跨域处理,但 ...
- wsl 2 unbuntu 部署 asp.net core 使用 nginx 做反向代理,调试文件上传失败
继上一篇 asp.net core 3.1多种身份验证方案,cookie和jwt混合认证授权 的公司内部项目上线后发现文件上传功能有问题. 上传的文件超过50M以后前端就报错了,没有状态返回,也没有响 ...
- nginx做反向代理并防盗链
nginx做反向代理真的非常简单,只需设置location+proxy_pass即可. 防盗链配置有些复杂,需要注意的地方: 在防盗链的location中需要再设置一下proxy_pass(在这里走了 ...
- 【Nginx】使用Nginx做反向代理时,关于被代理服务器相应的超时设置
> 参考的优秀文章 Module ngx_http_proxy_module > 设置等待被代理服务器的最大响应时间 使用Nginx做反向代理时,因被代理服务器因业务确实复杂,需时较久,往 ...
- Nginx做反向代理总是被系统kill
公司使用Nginx做反向代理,以前都挺正常的,最近不知怎么回事总是无端被系统kill,而在nginx错误日志中也没有信息输出. 网上查了很多资料,也没什么靠谱的回答,唯一觉得有点关联的就是linux ...
- Nginx做正向代理并缓存文件
和前面一篇用Nginx做反向代理并缓存静态文件 差别仅在于这是内部机器用来通过Nginx上外网的方式. 其他配置差不多,仅在下面有点区别 server { listen 83; location / ...
随机推荐
- Windows7的MySQL数据库的安装
碰巧重装了系统,需要重新安装MySQL. 1.进入官网下载:https://dev.mysql.com/ 2.severonle 3.alt+n 4.alt+x
- 20172302 《Java软件结构与数据结构》第九周学习总结
2018年学习总结博客总目录:第一周 第二周 第三周 第四周 第五周 第六周 第七周 第八周 第九周 教材学习内容总结 第十五章 图 1.图:图(graph)是由一些点(vertex)和这些点之间的连 ...
- linux 校准时间
ntpdate cn.pool.ntp.org //查看硬件时间可以是用hwclock,hwclock --show 或者hwclock -r [root@localhost ~]# hwclock ...
- j2me必备之网络开发数据处理
第9章 无线网络开发MIDP提供了一组通用的网络开发接口,用来针对不同的无线网络应用可以采取不同的开发接口.基于CLDC的网络支持是由统一网络连接框架(Generic Connection Frame ...
- js实现截取或查找字符串中的子字符串
获取 答案: var string0="sss.sscdyfasdfdgfg";//sscdy获取 ,); 答案是采用substr方法. 定义和用法:substr方法用于返回一个从 ...
- Linux学习笔记13—Vi编辑器的学习
文本编辑工具vim.vi1. vim与vi的最大区别是vim编辑的时候是带颜色显示的.Vi不带颜色显示.2. yum install -y vim-enhanced 如果没有安装VIM 使用上面的命令 ...
- quartus II输入原理图及仿真步骤
在Quartus II中输入原理图以及实现仿真是学习基本数字电路的好方法.下面以一个基本的D锁存器为例,在quartus II 13.0中一步一步来实现原理图输入以及仿真过程. 1,创建工程 指定工程 ...
- 奇怪吸引子---LorenzStenflo
奇怪吸引子是混沌学的重要组成理论,用于演化过程的终极状态,具有如下特征:终极性.稳定性.吸引性.吸引子是一个数学概念,描写运动的收敛类型.它是指这样的一个集合,当时间趋于无穷大时,在任何一个有界集上出 ...
- 05-树9 Huffman Codes及基本操作
哈夫曼树与哈弗曼编码 哈夫曼树 带权路径长度(WPL):设二叉树有n个叶子结点,每个叶子结点带有权值 Wk,从根结点到每个叶子结点的长度为 Lk,则每个叶子结点的带权路径长度之和就是: WPL = 最 ...
- 用户人品预测大赛--getmax队--竞赛分享
用户人品预测大赛--getmax队--竞赛分享 DataCastle运营 发表于 2016-3-24 14:49:32 533 0 0 答辩PPT