推荐 最新
万码用户

nginx-proxy-manager

它开箱即用支持 Docker 一键部署,可以让用户通过 Web 界面在线配置、管理 Nginx 服务,支持转发、重定向、SSL 证书、高级配置等功能。

11
0
0
浏览量71
sssssjkl

证书链完整,okhttp3请求错误?

证书情况 "myssl.com"验证证书是正常的 "https://myssl.com/ynslyszx.com" (https://link.segmentfault.com/?enc=Rl58bPUsLiXYbKR4SPkgog%3D%3D.BlyaOYBBPkulzooS98TibCDfCcm03tjWdZTvEPlpC2U%3D) 浏览器中查看 "image.png" (https://wmprod.oss-cn-shanghai.aliyuncs.com/images/20250121/0a265834b3836233c2083ad2f3fb6134.png) 使用命令查看 "image.png" (https://wmprod.oss-cn-shanghai.aliyuncs.com/images/20250121/be59a99dd5ffb7bb1928f0e025ce0bab.png) 测试代码 public static void main(String[] args) { String url = "https://ynslyszx.com/fp04/ldt-service/msp/getPublicKey.do"; OkHttpClient client = new OkHttpClient(); // 指定你要请求的URL Request request = new Request.Builder() .url(url) .build(); try (Response response = client.newCall(request).execute()) { if (!response.isSuccessful()) { throw new IOException("Unexpected code " + response); } // 打印响应体的内容 System.out.println(response.body().string()); } catch (IOException e) { e.printStackTrace(); } } 错误信息 使用okhttp请求报错: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target at sun.security.ssl.Alert.createSSLException(Alert.java:131) at sun.security.ssl.TransportContext.fatal(TransportContext.java:353) at sun.security.ssl.TransportContext.fatal(TransportContext.java:296) at sun.security.ssl.TransportContext.fatal(TransportContext.java:291) at sun.security.ssl.CertificateMessage$T12CertificateConsumer.checkServerCerts(CertificateMessage.java:652) at sun.security.ssl.CertificateMessage$T12CertificateConsumer.onCertificate(CertificateMessage.java:471) at sun.security.ssl.CertificateMessage$T12CertificateConsumer.consume(CertificateMessage.java:367) at sun.security.ssl.SSLHandshake.consume(SSLHandshake.java:376) at sun.security.ssl.HandshakeContext.dispatch(HandshakeContext.java:444) at sun.security.ssl.HandshakeContext.dispatch(HandshakeContext.java:422) at sun.security.ssl.TransportContext.dispatch(TransportContext.java:183) at sun.security.ssl.SSLTransport.decode(SSLTransport.java:154) at sun.security.ssl.SSLSocketImpl.decode(SSLSocketImpl.java:1279) at sun.security.ssl.SSLSocketImpl.readHandshakeRecord(SSLSocketImpl.java:1188) at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:401) at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:373) at okhttp3.internal.connection.RealConnection.connectTls(RealConnection.kt:379) at okhttp3.internal.connection.RealConnection.establishProtocol(RealConnection.kt:337) at okhttp3.internal.connection.RealConnection.connect(RealConnection.kt:209) at okhttp3.internal.connection.ExchangeFinder.findConnection(ExchangeFinder.kt:226) at okhttp3.internal.connection.ExchangeFinder.findHealthyConnection(ExchangeFinder.kt:106) at okhttp3.internal.connection.ExchangeFinder.find(ExchangeFinder.kt:74) at okhttp3.internal.connection.RealCall.initExchange$okhttp(RealCall.kt:255) at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.kt:32) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.kt:95) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:83) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:76) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109) at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:201) at okhttp3.internal.connection.RealCall.execute(RealCall.kt:154) at org.example.App.main(App.java:35) Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:439) at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:306) at sun.security.validator.Validator.validate(Validator.java:271) at sun.security.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:312) at sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:221) at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:128) at sun.security.ssl.CertificateMessage$T12CertificateConsumer.checkServerCerts(CertificateMessage.java:636) ... 29 more Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target at sun.security.provider.certpath.SunCertPathBuilder.build(SunCertPathBuilder.java:141) at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:126) at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:280) at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:434) ... 35 more 问题 1. 同样的代码,请求"https://baidu.com" (https://link.segmentfault.com/?enc=LAsp%2FXr6f6q8V1UnW07%2FBA%3D%3D.VaQZUVr0UBPH5NOsd9mM%2BBVBBQIxSjUsmimAlhCsqoU%3D)或"https://qq.com" (https://link.segmentfault.com/?enc=q5rFqEJ56pJ4MsdHXM%2BI7A%3D%3D.0ENTZ1%2FO3icYP0ebmhX2CQ%3D%3D)是正常的,请求ynslyszx.com就出错;使用"myssl.com"验证后,证书也是正常的,请问是哪个环节出错? 2. 服务器中尝试用"myssl.com"修复过证书,也是请求不通。 3. 目前解决办法是使okhttp3忽略全部证书验证,但是这样不太合适,请问是否有其他解决方案?

16
1
0
浏览量333
周舟莫UI设计

前端上线地址跨域?

在前端访问后端已经上线的地址,如果出现跨域可以用devserve代理解决吗?我认为是可以的,但是在群里跟别人讨论都说是后端配置的,我的理解是在开发阶段可以使用代理,然后项目上线后,一个后端服务可以对应多个前端项目,如果部署在一起的话就不会存在跨域问题,如果不在一起,再去后端配置白名单这样,但是群里的人说直接让后端配置跨域,我认为如果后端配置之后那前端的代理不就没有意义了吗?

16
1
0
浏览量288
雾里

小网站有必要将图片放到阿里云OSS存储吗?

网站有涉及到图片的请求,买了阿里云服务,我想将图片放在云服务上的某个目录下,然后通过nginx代理请求图片资源,不知道这么做是否可行? 还是说需要将图片放在OSS上存储,但是OSS需要收费? 哪个方案更好一些?

9
1
0
浏览量383
兰豆儿

请问 nginx 如何使用 iis 的 ssl?

举例目前 DMZ Linux 上安装 ngnix 但是SSL证书不安装在其上,安装在反向代理的 IIS server 上 nginx 只做转发动作 目前做 server{ port 443; location / { iis_server_ip } } 会得到 This site can’t provide a secure connection 错误

9
1
0
浏览量372
后端求offer版

【Nginx】实现负载均衡、限流、缓存、黑白名单和灰度发布,这是最全的一篇了!(建议收藏)

Nginx安装注意:这里以CentOS 6.8服务器为例,以root用户身份来安装Nginx。1.安装依赖环境yum -y install wget gcc-c++ ncurses ncurses-devel cmake make perl bison openssl openssl-devel gcc* libxml2 libxml2-devel curl-devel libjpeg* libpng* freetype* autoconf automake zlib* fiex* libxml* libmcrypt* libtool-ltdl-devel* libaio libaio-devel bzr libtool 2.安装opensslwget https://www.openssl.org/source/openssl-1.0.2s.tar.gz tar -zxvf openssl-1.0.2s.tar.gz cd /usr/local/src/openssl-1.0.2s ./config --prefix=/usr/local/openssl-1.0.2s make make install 3.安装pcrewget https://ftp.pcre.org/pub/pcre/pcre-8.43.tar.gz tar -zxvf pcre-8.43.tar.gz cd /usr/local/src/pcre-8.43 ./configure --prefix=/usr/local/pcre-8.43 make make install 4.安装zlibwget https://sourceforge.net/projects/libpng/files/zlib/1.2.11/zlib-1.2.11.tar.gz tar -zxvf zlib-1.2.11.tar.gz cd /usr/local/src/zlib-1.2.11 ./configure --prefix=/usr/local/zlib-1.2.11 make make 5.安装Nginxwget http://nginx.org/download/nginx-1.17.2.tar.gz tar -zxvf nginx-1.17.2.tar.gz cd /usr/local/src/nginx-1.17.2 ./configure --prefix=/usr/local/nginx-1.17.2 --with-openssl=/usr/local/src/openssl-1.0.2s --with-pcre=/usr/local/src/pcre-8.43 --with-zlib=/usr/local/src/zlib-1.2.11 --with-http_ssl_module make make install 这里需要注意的是:安装Nginx时,指定的是openssl、pcre和zlib的源码解压目录,安装完成后Nginx配置文件的完整路径为:/usr/local/nginx-1.17.2/conf/nginx.conf。Nginx负载均衡配置1.负载均衡配置http { …… upstream real_server { server 192.168.103.100:2001 weight=1; #轮询服务器和访问权重 server 192.168.103.100:2002 weight=2; } server { listen 80; location / { proxy_pass http://real_server; } } } 2.失败重试配置upstream real_server { server 192.168.103.100:2001 weight=1 max_fails=2 fail_timeout=60s; server 192.168.103.100:2002 weight=2 max_fails=2 fail_timeout=60s; } 意思是在fail_timeout时间内失败了max_fails次请求后,则认为该上游服务器不可用,然后将该服务地址踢除掉。fail_timeout时间后会再次将该服务器加入存活列表,进行重试。Nginx限流配置1.配置参数limit_req_zone指令设置参数limit_req_zone $binary_remote_addr zone=mylimit:10m rate=10r/s; limit_req_zone定义在http块中,$binary_remote_addr表示保存客户端IP地址的二进制形式。Zone定义IP状态及URL访问频率的共享内存区域。zone=keyword标识区域的名字,以及冒号后面跟区域大小。16000个IP地址的状态信息约1MB,所以示例中区域可以存储160000个IP地址。Rate定义最大请求速率。示例中速率不能超过每秒10个请求。2.设置限流location / { limit_req zone=mylimit burst=20 nodelay; proxy_pass http://real_server; } burst排队大小,nodelay不限制单个请求间的时间。3.不限流白名单geo $limit { default 1; 192.168.2.0/24 0; } map $limit $limit_key { 1 $binary_remote_addr; 0 ""; } limit_req_zone $limit_key zone=mylimit:10m rate=1r/s; location / { limit_req zone=mylimit burst=1 nodelay; proxy_pass http://real_server; } 上述配置中,192.168.2.0/24网段的IP访问是不限流的,其他限流。IP后面的数字含义:24表示子网掩码:255.255.255.016表示子网掩码:255.255.0.08表示子网掩码:255.0.0.0Nginx缓存配置1.浏览器缓存静态资源缓存用expirelocation ~* .(jpg|jpeg|png|gif|ico|css|js)$ { expires 2d; } Response Header中添加了Expires和Cache-Control,静态资源包括(一般缓存)普通不变的图像,如logo,图标等js、css静态文件可下载的内容,媒体文件协商缓存(add_header ETag/Last-Modified value)HTML文件经常替换的图片经常修改的js、css文件基本不变的API接口不需要缓存用户隐私等敏感数据经常改变的api数据接口2.代理层缓存//缓存路径,inactive表示缓存的时间,到期之后将会把缓存清理 proxy_cache_path /data/cache/nginx/ levels=1:2 keys_zone=cache:512m inactive = 1d max_size=8g; location / { location ~ \.(htm|html)?$ { proxy_cache cache; proxy_cache_key $uri$is_args$args; //以此变量值做HASH,作为KEY //HTTP响应首部可以看到X-Cache字段,内容可以有HIT,MISS,EXPIRES等等 add_header X-Cache $upstream_cache_status; proxy_cache_valid 200 10m; proxy_cache_valid any 1m; proxy_pass http://real_server; proxy_redirect off; } location ~ .*\.(gif|jpg|jpeg|bmp|png|ico|txt|js|css)$ { root /data/webapps/edc; expires 3d; add_header Static Nginx-Proxy; } } 在本地磁盘创建一个文件目录,根据设置,将请求的资源以K-V形式缓存在此目录当中,KEY需要自己定义(这里用的是url的hash值),同时可以根据需要指定某内容的缓存时长,比如状态码为200缓存10分钟,状态码为301,302的缓存5分钟,其他所有内容缓存1分钟等等。可以通过purger的功能清理缓存。AB测试/个性化需求时应禁用掉浏览器缓存。Nginx黑名单1.一般配置location / { deny 192.168.1.1; deny 192.168.1.0/24; allow 10.1.1.0/16; allow 2001:0db8::/32; deny all; } 2. Lua+Redis动态黑名单(OpenResty)安装运行yum install yum-utils yum-config-manager --add-repo https://openresty.org/package/centos/openresty.repo yum install openresty yum install openresty-resty 查看 yum --disablerepo="*" --enablerepo="openresty" list available 运行 service openresty start 配置(/usr/local/openresty/nginx/conf/nginx.conf)lua_shared_dict ip_blacklist 1m; server { listen 80; location / { access_by_lua_file lua/ip_blacklist.lua; proxy_pass http://real_server; } } lua脚本(ip_blacklist.lua)local redis_host = "192.168.1.132" local redis_port = 6379 local redis_pwd = 123456 local redis_db = 2 -- connection timeout for redis in ms. local redis_connection_timeout = 100 -- a set key for blacklist entries local redis_key = "ip_blacklist" -- cache lookups for this many seconds local cache_ttl = 60 -- end configuration local ip = ngx.var.remote_addr local ip_blacklist = ngx.shared.ip_blacklist local last_update_time = ip_blacklist:get("last_update_time"); -- update ip_blacklist from Redis every cache_ttl seconds: if last_update_time == nil or last_update_time < ( ngx.now() - cache_ttl ) then local redis = require "resty.redis"; local red = redis:new(); red:set_timeout(redis_connect_timeout); local ok, err = red:connect(redis_host, redis_port); if not ok then ngx.log(ngx.ERR, "Redis connection error while connect: " .. err); else local ok, err = red:auth(redis_pwd) if not ok then ngx.log(ngx.ERR, "Redis password error while auth: " .. err); else local new_ip_blacklist, err = red:smembers(redis_key); if err then ngx.log(ngx.ERR, "Redis read error while retrieving ip_blacklist: " .. err); else ngx.log(ngx.ERR, "Get data success:" .. new_ip_blacklist) -- replace the locally stored ip_blacklist with the updated values: ip_blacklist:flush_all(); for index, banned_ip in ipairs(new_ip_blacklist) do ip_blacklist:set(banned_ip, true); end -- update time ip_blacklist:set("last_update_time", ngx.now()); end end end end if ip_blacklist:get(ip) then ngx.log(ngx.ERR, "Banned IP detected and refused access: " .. ip); return ngx.exit(ngx.HTTP_FORBIDDEN); end Nginx灰度发布1.根据Cookie实现灰度发布根据Cookie查询version值,如果该version值为v1转发到host1,为v2转发到host2,都不匹配的情况下转发到默认配置。upstream host1 { server 192.168.2.46:2001 weight=1; #轮询服务器和访问权重 server 192.168.2.46:2002 weight=2; } upstream host2 { server 192.168.1.155:1111 max_fails=1 fail_timeout=60; } upstream default { server 192.168.1.153:1111 max_fails=1 fail_timeout=60; } map $COOKIE_version $group { ~*v1$ host1; ~*v2$ host2; default default; } lua_shared_dict ip_blacklist 1m; server { listen 80; #set $group "default"; #if ($http_cookie ~* "version=v1"){ # set $group host1; #} #if ($http_cookie ~* "version=v2"){ # set $group host2; #} location / { access_by_lua_file lua/ip_blacklist.lua; proxy_pass http://$group; } } 2.根据来路IP实现灰度发布server { …………… set $group default; if ($remote_addr ~ "192.168.119.1") { set $group host1; } if ($remote_addr ~ "192.168.119.2") { set $group host2; }

0
0
0
浏览量2076
后端求offer版

【Nginx】面试官问我Nginx能不能配置WebSocket?我给他现场演示了一番!!

写在前面当今互联网领域,不管是APP还是H5,不管是微信端还是小程序,只要是一款像样点的产品,为了增加用户的交互感和用户粘度,多多少少都会涉及到聊天功能。而对于Web端与H5来说,实现聊天最简单的就是使用WebSocket了。而在实现WebSocket聊天的过程中,后台也往往会部署多个WebSocket服务,多个WebSocket服务之间,可以通过Nginx进行负载均衡。今天,我们就来一起说说Nginx是如何配置WebSocket的。Nginx配置WebSocketNginx配置WebSocket也比较简单,只需要在nginx.conf文件中进行相应的配置。这种方式很简单,但是很有效,能够横向扩展WebSocket服务端的服务能力。先直接展示配置文件,如下所示(使用的话直接复制,然后改改ip和port即可)map $http_upgrade $connection_upgrade { default upgrade; '' close; } upstream wsbackend{ server ip1:port1; server ip2:port2; keepalive 1000; } server { listen 20038; location /{ proxy_http_version 1.1; proxy_pass http://wsbackend; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_read_timeout 3600s; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; } } 接下来,我们就分别分析上述配置的具体含义。首先:map $http_upgrade $connection_upgrade { default upgrade; '' close; } 表示的是:如果 $http_upgrade 不为 '' (空),则 $connection_upgrade 为 upgrade 。如果 $http_upgrade 为 '' (空),则 $connection_upgrade 为 close。其次:upstream wsbackend{ server ip1:port1; server ip2:port2; keepalive 1000; } 表示的是 nginx负载均衡:两台服务器 (ip1:port1)和(ip2:port2) 。keepalive 1000 表示的是每个nginx进程中上游服务器保持的空闲连接,当空闲连接过多时,会关闭最少使用的空闲连接.当然,这不是限制连接总数的,可以想象成空闲连接池的大小,设置的值应该是上游服务器能够承受的。最后:server { listen 20038; location /{ proxy_http_version 1.1; proxy_pass http://wsbackend; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_read_timeout 3600s; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; } } 表示的是监听的服务器的配置listen 20038 表示 nginx 监听的端口locations / 表示监听的路径(/表示所有路径,通用匹配,相当于default)proxt_http_version 1.1 表示反向代理发送的HTTP协议的版本是1.1,HTTP1.1支持长连接proxy_pass http://wsbackend; 表示反向代理的uri,这里可以使用负载均衡变量proxy_redirect off; 表示不要替换路径,其实这里如果是/则有没有都没关系,因为default也是将路径替换到proxy_pass的后边Host $host; 表示传递时请求头不变, $host是nginx内置变量,表示的是当前的请求头,proxy_set_header表示设置请求头proxy_set_header X-Real-IP $remote_addr; 表示传递时来源的ip还是现在的客户端的ipproxy_read_timeout 3600s; 表的两次请求之间的间隔超过 3600s 后才关闭这个连接,默认的60s,自动关闭的元凶proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 表示X-Forwarded-For头不发生改变proxy_set_header Upgrade $http_upgrade; 表示设置Upgrade不变proxy_set_header Connection $connection_upgrade; 表示如果 $http_upgrade为upgrade,则请求为upgrade(websocket),如果不是,就关闭连接

0
0
0
浏览量2041
后端求offer版

【Nginx】如何使用Nginx搭建流媒体服务器实现直播?看完这篇我会了!!

写在前面最近几年,直播行业比较火,无论是传统行业的直播,还是购物、游戏、教育,都在涉及直播。作为在互联网行业奋斗了多年的小伙伴,你有没有想过如果使用Nginx搭建一套直播环境,那我们该如何搭建呢?别急,接下来,我们就一起使用Nginx来搭建一套直播环境。安装Nginx注意:这里以CentOS 6.8服务器为例,以root用户身份来安装Nginx。1.安装依赖环境yum -y install wget gcc-c++ ncurses ncurses-devel cmake make perl bison openssl openssl-devel gcc* libxml2 libxml2-devel curl-devel libjpeg* libpng* freetype* autoconf automake zlib* fiex* libxml* libmcrypt* libtool-ltdl-devel* libaio libaio-devel bzr libtool 2.安装opensslwget https://www.openssl.org/source/openssl-1.0.2s.tar.gz tar -zxvf openssl-1.0.2s.tar.gz cd /usr/local/src/openssl-1.0.2s ./config --prefix=/usr/local/openssl-1.0.2s make make install 3.安装pcrewget https://ftp.pcre.org/pub/pcre/pcre-8.43.tar.gz tar -zxvf pcre-8.43.tar.gz cd /usr/local/src/pcre-8.43 ./configure --prefix=/usr/local/pcre-8.43 make make install 4.安装zlibwget https://sourceforge.net/projects/libpng/files/zlib/1.2.11/zlib-1.2.11.tar.gz tar -zxvf zlib-1.2.11.tar.gz cd /usr/local/src/zlib-1.2.11 ./configure --prefix=/usr/local/zlib-1.2.11 make make 5.下载nginx-rtmp-modulenginx-rtmp-module的官方github地址:github.com/arut/nginx-…使用命令:git clone https://github.com/arut/nginx-rtmp-module.git 6.安装Nginxwget http://nginx.org/download/nginx-1.19.1.tar.gz tar -zxvf nginx-1.19.1.tar.gz cd /usr/local/src/nginx-1.19.1 ./configure --prefix=/usr/local/nginx-1.19.1 --with-openssl=/usr/local/src/openssl-1.0.2s --with-pcre=/usr/local/src/pcre-8.43 --with-zlib=/usr/local/src/zlib-1.2.11 --add-module=/usr/local/src/nginx-rtmp-module --with-http_ssl_module make make install 这里需要注意的是:安装Nginx时,指定的是openssl、pcre和zlib的源码解压目录,安装完成后Nginx配置文件的完整路径为:/usr/local/nginx-1.19.1/conf/nginx.conf。配置Nginx配置Nginx主要是对Nginx的nginx.conf文件进行配置,我们可以在命令行输入如下命令编辑nginx.conf文件。vim /usr/local/nginx-1.19.1/conf/nginx.conf 在文件中添加如下内容。rtmp { server { listen 1935; #监听的端口 chunk_size 4096; application hls { #rtmp推流请求路径 live on; hls on; hls_path /usr/share/nginx/html/hls; hls_fragment 5s; } } } 其中,hls_path需要可读可写的权限。接下来,我们创建/usr/share/nginx/html/hls 目录。mkdir -p /usr/share/nginx/html/hls chmod -R 777 /usr/share/nginx/html/hls 接下来,修改http中的server模块:server { listen 81; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root /usr/share/nginx/html; index index.html index.htm; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } 然后启动Nginx:/usr/local/nginx-1.19.1/sbin/nginx -c /usr/local/nginx-1.19.1/conf/nginx.conf 使OBS推流OBS(Open Broadcaster Software) 是以互联网流媒体直播内容为目的免费和开放源码软件。需要下载这个软件,借助这个软件进行推流(电脑没有摄像头的貌似安装不了。。。)OBS的下载链接为: https://obsproject.com/zh-cn/download%E3%80%82 安装后,桌面上会有一个如下所示的图表。打开后我们需要有一个场景,并且在这个场景下有一个流的来源(可以是窗口,如果选的是视频则会自动识别摄像头),接下来就是设置了。在配置中最需要关注的就是流的配置,由于是自建的流媒体服务器所以我们按照如下所示的方式进行配置。rtmp://你的服务器ip:端口(1935)/live #URL填写流的地址 设置完成我们就可以  开始推流了。拉流测试地址推荐一个拉流的测试地址,里面针对各种协议都能测试拉流测试,需要注意图中几个地方,由于我们使用的rtmp协议,我们选择这一栏,底下填写我们推流的地址和我们在上面obs的设置里面配置的流的名称,start, ok搞定!!!

0
0
0
浏览量2029
后端求offer版

【Nginx】如何使用Nginx实现MySQL数据库的负载均衡?看完我懂了!!

写在前面Nginx能够实现HTTP、HTTPS协议的负载均衡,也能够实现TCP协议的负载均衡。那么,问题来了,可不可以通过Nginx实现MySQL数据库的负载均衡呢?答案是:可以。接下来,就让我们一起探讨下如何使用Nginx实现MySQL的负载均衡。前提条件注意:使用Nginx实现MySQL数据库的负载均衡,前提是要搭建MySQL的主主复制环境,关于MySQL主主复制环境的搭建,后续会在MySQL专题为大家详细阐述。这里,我们假设已经搭建好MySQL的主主复制环境,MySQL服务器的IP和端口分别如下所示。192.168.1.101    3306192.168.1.102    3306通过Nginx访问MySQL的IP和端口如下所示。192.168.1.100    3306Nginx实现MySQL负载均衡nginx在版本1.9.0以后支持tcp的负载均衡,具体可以参照官网关于模块ngx_stream_core_module的叙述,链接地址为:nginx.org/en/docs/str…nginx从1.9.0后引入模块ngx_stream_core_module,模块是没有编译的,需要用到编译,编译时需添加--with-stream配置参数,stream负载均衡官方配置样例如下所示。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; proxy_responses 1; proxy_timeout 20s; proxy_pass dns; } server { listen [::1]:12345; proxy_pass unix:/tmp/stream.socket; } } 说到这里,使用Nginx实现MySQL的负载均衡就比较简单了。我们可以参照上面官方的配置示例来配置MySQL的负载均衡。这里,我们可以将Nginx配置成如下所示。user nginx; #user root; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; 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; keepalive_timeout 65; #gzip on; include /etc/nginx/conf.d/*.conf; } stream{ upstream mysql{ server 192.168.1.101:3306 weight=1; server 192.168.1.102:3306 weight=1; } server{ listen 3306; server_name 192.168.1.100; proxy_pass mysql; } } 配置完成后,我们就可以通过如下方式来访问MySQL数据库。jdbc:mysql://192.168.1.100:3306/数据库名称 此时,Nginx会将访问MySQL的请求路由到IP地址为192.168.1.101和192.168.1.102的MySQL上。

0
0
0
浏览量2036
后端求offer版

【Nginx】如何封禁IP和IP段?看完这篇我会了!!

写在前面Nginx不仅仅只是一款反向代理和负载均衡服务器,它还能提供很多强大的功能,例如:限流、缓存、黑白名单和灰度发布等等。在之前的文章中,我们已经介绍了Nginx提供的这些功能。小伙伴们可以到【Nginx专题】进行查阅。今天,我们来介绍Nginx另一个强大的功能:禁用IP和IP段。禁用IP和IP段Nginx的ngx_http_access_module 模块可以封配置内的ip或者ip段,语法如下:deny IP; deny subnet; allow IP; allow subnet; # block all ips deny all; # allow all ips allow all; 如果规则之间有冲突,会以最前面匹配的规则为准。配置禁用ip和ip段下面说明假定nginx的目录在/usr/local/nginx/。首先要建一个封ip的配置文件blockips.conf,然后vi blockips.conf编辑此文件,在文件中输入要封的ip。deny 1.2.3.4; deny 91.212.45.0/24; deny 91.212.65.0/24; 然后保存此文件,并且打开nginx.conf文件,在http配置节内添加下面一行配置:include blockips.conf; 保存nginx.conf文件,然后测试现在的nginx配置文件是否是合法的:/usr/local/nginx/sbin/nginx -t 如果配置没有问题,就会输出:the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok configuration file /usr/local/nginx/conf/nginx.conf test is successful 如果配置有问题就需要检查下哪儿有语法问题,如果没有问题,需要执行下面命令,让nginx重新载入配置文件。/usr/local/nginx/sbin/nginx -s reload 仅允许内网ip如何禁止所有外网ip,仅允许内网ip呢?如下配置文件location / { # block one workstation deny 192.168.1.1; # allow anyone in 192.168.1.0/24 allow 192.168.1.0/24; # drop rest of the world deny all; } 上面配置中禁止了192.168.1.1,允许其他内网网段,然后deny all禁止其他所有ip。格式化nginx的403页面如何格式化nginx的403页面呢?首先执行下面的命令:cd /usr/local/nginx/html vi error403.html 然后输入403的文件内容,例如:<html> <head><title>Error 403 - IP Address Blocked</title></head> <body> Your IP Address is blocked. If you this an error, please contact binghe with your IP at test@binghe.com </body> </html> 如果启用了SSI,可以在403中显示被封的客户端ip,如下:Your IP Address is <!--#echo var="REMOTE_ADDR" --> blocked. 保存error403文件,然后打开nginx的配置文件vi nginx.conf,在server配置节内添加下面内容。# redirect server error pages to the static page error_page 403 /error403.html; location = /error403.html { root html; }

0
0
0
浏览量2026