NGINX监听IPV6

什么是 Nginx?

Nginx
Nginx(发音为“engine-x”)是用于 HTTP、HTTPS、SMTP、POP3 和 IMAP 协议的开源反向代理服务器,以及负载均衡器、HTTP 缓存和 Web 服务器(源服务器)。nginx 项目一开始就非常关注高并发、高性能和低内存使用。它在 2 条款 BSD-like 许可证下获得许可,它可以在 Linux、BSD 变体、Mac OS X、Solaris、AIX、HP-UX 以及其他 *nix 风格上运行。它还具有 Microsoft Windows 的概念验证端口。

Nginx监听IPv6地址端口的正确操作方法

IPV4日益稀缺,ipv6已经慢慢走上日程,待ipv6在国内普及,使用nginx配置ipv6那是肯定的,看看如何让nginx支持ipv6以及配置。
查看nginx是否支持ipv6

[root@localhost ~]# nginx -V

nginx version: openresty/1.19.9.1
built with OpenSSL 1.1.1l 24 Aug 2021
TLS SNI support enabled
configure arguments: --prefix=/usr/local/openresty/nginx --with-cc-opt=‘-O2 -DNGX_LUA_ABORT_AT_PANIC ···
rpath,/usr/local/openresty/zlib/lib:/usr/local/openresty/pcre/lib:/usr/local/openresty/openssl111/lib’ --with-pcre-jit --with-stream --with-stream_ssl_module --with-stream_ssl_preread_module --with-http_v2_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --with-http_stub_status_module --with-http_realip_module --with-http_addition_module --with-http_auth_request_module --with-http_secure_link_module --with-http_random_index_module --with-http_gzip_static_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-threads --with-stream --with-http_ssl_module
root@insightone-ui:/usr/local/openresty# nginx -v
nginx version: openresty/1.19.9.1
没有出现--with-ipv6,说明当前的nginx不支持ipv6,所以我们需要重新编译nginx,配置里面增加–with-ipv6,具体怎么安装,我不在啰嗦了。

Nginx 1.3.4的某个版本起,默认ipv6only是打开的,所以我们只需要在监听中加入ipv6监听即可,不过推荐都手动加上比较好,代码如下:
同时监听IPV4和IPV6

server {
    
    
  listen [::]:80;
  listen [::]:80 ipv6only=on;
}

如果只想监听ipv6,则去掉ipv4的配置,然后将ipv6设置为默认即可

server {
    
    
  listen [::]:80 default ipv6only=on;
}

如果想监听指定ipv6地址,则将中括号中的::换成指定ipv6地址即可

server {
    
    
  listen [3608:f0f0:3002:31::1]:80;
}

在运行时控制 NGINX 进程

主进程和工作进程
NGINX 有一个主进程和一个或多个工作进程。如果启用缓存,缓存加载器和缓存管理器进程也会在启动时运行。
主进程的主要目的是读取和评估配置文件,以及维护工作进程。工作进程对请求进行实际处理。NGINX 依靠依赖于操作系统的机制在工作进程之间有效地分配请求。工作进程的数量由nginx.conf配置文件中的worker_processes指令定义,可以设置为固定数量,也可以配置为自动调整为可用 CPU 内核的数量。
控制 NGINX
要重新加载配置,您可以停止或重新启动 NGINX,或向主进程发送信号。可以通过运行带有参数的nginx命令(调用 NGINX 可执行文件)来发送信号。-s

nginx -s <SIGNAL>

其中<SIGNAL>可以是以下之一:

quit 优雅地关闭(SIGQUIT信号)
reload 重新加载配置文件(SIGHUP信号)
reopen 重新打开日志文件(SIGUSR1信号)
stop 立即关机(或快速关机,SIGTERM信号)

该kill实用程序还可用于直接向主进程发送信号。默认情况下主进程的进程ID写入nginx.pid文件,该文件位于/usr/local/nginx/logs或/var/run目录中

容器镜像

nginx.org changes page
自DockerNginx 1.11.5 版本以后,移除了 --with-ipv6 配置选项,现在为 ipv6 自动配置支持!
Don’t worry too much about the vague future, only to work hard for the clear now.

猜你喜欢

转载自blog.csdn.net/qq_50573146/article/details/126306033
今日推荐